Skip to content

Commit

Permalink
Fix redis states not applied to exports (#847)
Browse files Browse the repository at this point in the history
fixes #844
  • Loading branch information
nilmerg authored Sep 8, 2023
2 parents a1aa4cd + dfc5485 commit a076438
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
4 changes: 2 additions & 2 deletions library/Icingadb/Data/CsvResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions library/Icingadb/Data/JsonResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
22 changes: 19 additions & 3 deletions library/Icingadb/Redis/VolatileStateResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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<int, mixed> $rows
*
* @return void
*/
protected function applyRedisUpdates($rows)
{
$type = null;
$behaviors = null;
Expand All @@ -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);

Expand Down
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a076438

Please sign in to comment.