Skip to content

Commit 8085a11

Browse files
committed
Merge pull request #1058 from chuangbo/patch-1
Lazy load status data
2 parents 540ec92 + 81c8434 commit 8085a11

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file based on the
1616
`field` or `script` param.
1717
- `Elastica\Index->deleteByQuery($query, $options)` $query param can be a query `array` again
1818
- `Elastica\Query\MoreLikeThis->toArray()` now supports providing a non-indexed document as an input to perform the comparison.
19+
- `Elastica\Status` will lazy load the `_stats` at when it is needed.
1920

2021
### Deprecated
2122

lib/Elastica/Status.php

+11-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Status
2424
*
2525
* @var array Data
2626
*/
27-
protected $_data = array();
27+
protected $_data = null;
2828

2929
/**
3030
* Client object.
@@ -41,7 +41,6 @@ class Status
4141
public function __construct(Client $client)
4242
{
4343
$this->_client = $client;
44-
$this->refresh();
4544
}
4645

4746
/**
@@ -51,6 +50,9 @@ public function __construct(Client $client)
5150
*/
5251
public function getData()
5352
{
53+
if (is_null($this->_data)) {
54+
$this->refresh();
55+
}
5456
return $this->_data;
5557
}
5658

@@ -61,7 +63,8 @@ public function getData()
6163
*/
6264
public function getIndexNames()
6365
{
64-
return array_keys($this->_data['indices']);
66+
$data = $this->getData();
67+
return array_keys($data['indices']);
6568
}
6669

6770
/**
@@ -124,6 +127,9 @@ public function getIndicesWithAlias($alias)
124127
*/
125128
public function getResponse()
126129
{
130+
if (is_null($this->_response)) {
131+
$this->refresh();
132+
}
127133
return $this->_response;
128134
}
129135

@@ -134,7 +140,8 @@ public function getResponse()
134140
*/
135141
public function getShards()
136142
{
137-
return $this->_data['shards'];
143+
$data = $this->getData();
144+
return $data['shards'];
138145
}
139146

140147
/**

0 commit comments

Comments
 (0)