From 333c94f58954bd8f15c12a92f5e2f4b5e7c7b4be Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 21 Aug 2023 14:52:00 +0200 Subject: [PATCH 1/3] VolatileStateResults: Fetch individual redis results.. ..if the cache is disabled. --- .../Icingadb/Redis/VolatileStateResults.php | 22 ++++++++++++++++--- phpstan-baseline.neon | 5 ----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/library/Icingadb/Redis/VolatileStateResults.php b/library/Icingadb/Redis/VolatileStateResults.php index 81c117ff7..941839802 100644 --- a/library/Icingadb/Redis/VolatileStateResults.php +++ b/library/Icingadb/Redis/VolatileStateResults.php @@ -56,6 +56,15 @@ public function current() return parent::current(); } + public function next(): void + { + parent::next(); + + if (! $this->redisUnavailable && $this->isCacheDisabled && $this->valid()) { + $this->applyRedisUpdates([parent::current()]); + } + } + public function key(): int { if (! $this->redisUnavailable && ! $this->updatesApplied && ! $this->isCacheDisabled) { @@ -72,14 +81,21 @@ public function rewind(): void $this->advance(); Benchmark::measure('Applying Redis updates'); - $this->applyRedisUpdates(); + $this->applyRedisUpdates($this); Benchmark::measure('Redis updates applied'); } parent::rewind(); } - protected function applyRedisUpdates() + /** + * Apply redis state details to the given results + * + * @param self|array $rows + * + * @return void + */ + protected function applyRedisUpdates($rows) { $type = null; $behaviors = null; @@ -91,7 +107,7 @@ protected function applyRedisUpdates() $states = []; $hostStates = []; - foreach ($this as $row) { + foreach ($rows as $row) { if ($type === null) { $behaviors = $this->resolver->getBehaviors($row->state); diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index c685ff8c5..7db48279f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -5380,11 +5380,6 @@ parameters: count: 1 path: library/Icingadb/Redis/VolatileStateResults.php - - - message: "#^Method Icinga\\\\Module\\\\Icingadb\\\\Redis\\\\VolatileStateResults\\:\\:applyRedisUpdates\\(\\) has no return type specified\\.$#" - count: 1 - path: library/Icingadb/Redis/VolatileStateResults.php - - message: "#^Method Icinga\\\\Module\\\\Icingadb\\\\Redis\\\\VolatileStateResults\\:\\:parseDenylist\\(\\) should return ipl\\\\Stdlib\\\\Filter\\\\None but returns ipl\\\\Stdlib\\\\Filter\\\\Chain\\.$#" count: 1 From 57e6f3ce155ce85da7d71b85b50944f7d87e2432 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 21 Aug 2023 14:52:49 +0200 Subject: [PATCH 2/3] CsvResultSet: Extend `VolatileStateResults` --- library/Icingadb/Data/CsvResultSet.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/Icingadb/Data/CsvResultSet.php b/library/Icingadb/Data/CsvResultSet.php index 510db5cce..746a7e4a3 100644 --- a/library/Icingadb/Data/CsvResultSet.php +++ b/library/Icingadb/Data/CsvResultSet.php @@ -6,11 +6,11 @@ use DateTime; use DateTimeZone; +use Icinga\Module\Icingadb\Redis\VolatileStateResults; use ipl\Orm\Model; use ipl\Orm\Query; -use ipl\Orm\ResultSet; -class CsvResultSet extends ResultSet +class CsvResultSet extends VolatileStateResults { protected $isCacheDisabled = true; From dfc5485d45e6f231eab586781554fabf74870ada Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 21 Aug 2023 14:53:12 +0200 Subject: [PATCH 3/3] JsonResultSet: Extend `VolatileStateResults` --- library/Icingadb/Data/JsonResultSet.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/Icingadb/Data/JsonResultSet.php b/library/Icingadb/Data/JsonResultSet.php index b74effc6f..73cd9ef17 100644 --- a/library/Icingadb/Data/JsonResultSet.php +++ b/library/Icingadb/Data/JsonResultSet.php @@ -6,12 +6,12 @@ use DateTime; use DateTimeZone; +use Icinga\Module\Icingadb\Redis\VolatileStateResults; use Icinga\Util\Json; use ipl\Orm\Model; use ipl\Orm\Query; -use ipl\Orm\ResultSet; -class JsonResultSet extends ResultSet +class JsonResultSet extends VolatileStateResults { protected $isCacheDisabled = true;