From 46c464e3bf0941b0d22f5557f1012e2dd2a692aa Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 8 Oct 2021 16:22:24 +0200 Subject: [PATCH] VolatileStateResults: Prevent loops and handle empty results --- library/Icingadb/Redis/VolatileStateResults.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/library/Icingadb/Redis/VolatileStateResults.php b/library/Icingadb/Redis/VolatileStateResults.php index f1b30f64..d65e8bef 100644 --- a/library/Icingadb/Redis/VolatileStateResults.php +++ b/library/Icingadb/Redis/VolatileStateResults.php @@ -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);