Skip to content

Commit

Permalink
Merge pull request #1058 from chuangbo/patch-1
Browse files Browse the repository at this point in the history
Lazy load status data
  • Loading branch information
ruflin committed Mar 16, 2016
2 parents 540ec92 + 81c8434 commit 8085a11
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file based on the
`field` or `script` param.
- `Elastica\Index->deleteByQuery($query, $options)` $query param can be a query `array` again
- `Elastica\Query\MoreLikeThis->toArray()` now supports providing a non-indexed document as an input to perform the comparison.
- `Elastica\Status` will lazy load the `_stats` at when it is needed.

### Deprecated

Expand Down
15 changes: 11 additions & 4 deletions lib/Elastica/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Status
*
* @var array Data
*/
protected $_data = array();
protected $_data = null;

/**
* Client object.
Expand All @@ -41,7 +41,6 @@ class Status
public function __construct(Client $client)
{
$this->_client = $client;
$this->refresh();
}

/**
Expand All @@ -51,6 +50,9 @@ public function __construct(Client $client)
*/
public function getData()
{
if (is_null($this->_data)) {
$this->refresh();
}
return $this->_data;
}

Expand All @@ -61,7 +63,8 @@ public function getData()
*/
public function getIndexNames()
{
return array_keys($this->_data['indices']);
$data = $this->getData();
return array_keys($data['indices']);
}

/**
Expand Down Expand Up @@ -124,6 +127,9 @@ public function getIndicesWithAlias($alias)
*/
public function getResponse()
{
if (is_null($this->_response)) {
$this->refresh();
}
return $this->_response;
}

Expand All @@ -134,7 +140,8 @@ public function getResponse()
*/
public function getShards()
{
return $this->_data['shards'];
$data = $this->getData();
return $data['shards'];
}

/**
Expand Down

0 comments on commit 8085a11

Please sign in to comment.