VolatileStateResults: Prevent loops and handle empty results

This commit is contained in:
Johannes Meyer 2021-10-08 16:22:24 +02:00
parent ddbac68f94
commit 46c464e3bf

View file

@ -15,9 +15,12 @@ use RuntimeException;
class VolatileStateResults extends ResultSet
{
/** @var bool Whether Redis updates were applied */
private $updatesApplied = false;
public function current()
{
if ($this->position === null && ! $this->isCacheDisabled) {
if (! $this->updatesApplied && ! $this->isCacheDisabled) {
$this->rewind();
}
@ -26,7 +29,7 @@ class VolatileStateResults extends ResultSet
public function key()
{
if ($this->position === null && ! $this->isCacheDisabled) {
if (! $this->updatesApplied && ! $this->isCacheDisabled) {
$this->rewind();
}
@ -35,7 +38,8 @@ class VolatileStateResults extends ResultSet
public function rewind()
{
if ($this->position === null && ! $this->isCacheDisabled) {
if (! $this->updatesApplied && ! $this->isCacheDisabled) {
$this->updatesApplied = true;
$this->advance();
Benchmark::measure('Applying Redis updates');
@ -75,6 +79,10 @@ class VolatileStateResults extends ResultSet
}
}
if (empty($states)) {
return;
}
foreach ($this->fetchStates("icinga:{$type}:state", array_keys($states)) as $id => $data) {
foreach ($data as $key => $value) {
$data[$key] = $behaviors->retrieveProperty($value, $key);