Skip to content

Commit

Permalink
Use separate result sets when exporting hosts/services
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg committed Mar 22, 2024
1 parent 0148984 commit e311d8b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
4 changes: 2 additions & 2 deletions library/Icingadb/Data/CsvResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Icinga\Module\Icingadb\Data;

use Icinga\Module\Icingadb\Redis\VolatileStateResults;
use ipl\Orm\ResultSet;

class CsvResultSet extends VolatileStateResults
class CsvResultSet extends ResultSet
{
use CsvResultSetUtils;
}
8 changes: 7 additions & 1 deletion library/Icingadb/Data/CsvResultSetUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use DateTime;
use DateTimeZone;
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Module\Icingadb\Model\Service;
use ipl\Orm\Model;
use ipl\Orm\Query;

Expand Down Expand Up @@ -65,7 +67,11 @@ protected function extractKeysAndValues(Model $model, string $path = ''): array

public static function stream(Query $query): void
{
$query->setResultSetClass(__CLASS__);
if ($query->getModel() instanceof Host || $query->getModel() instanceof Service) {
$query->setResultSetClass(VolatileCsvResults::class);
} else {
$query->setResultSetClass(__CLASS__);
}

foreach ($query->execute()->disableCache() as $i => $keysAndValues) {
if ($i === 0) {
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 @@ -4,9 +4,9 @@

namespace Icinga\Module\Icingadb\Data;

use Icinga\Module\Icingadb\Redis\VolatileStateResults;
use ipl\Orm\ResultSet;

class JsonResultSet extends VolatileStateResults
class JsonResultSet extends ResultSet
{
use JsonResultSetUtils;
}
8 changes: 7 additions & 1 deletion library/Icingadb/Data/JsonResultSetUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use DateTime;
use DateTimeZone;
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Module\Icingadb\Model\Service;
use Icinga\Util\Json;
use ipl\Orm\Model;
use ipl\Orm\Query;
Expand Down Expand Up @@ -59,7 +61,11 @@ protected function createObject(Model $model): array

public static function stream(Query $query): void
{
$query->setResultSetClass(__CLASS__);
if ($query->getModel() instanceof Host || $query->getModel() instanceof Service) {
$query->setResultSetClass(VolatileJsonResults::class);
} else {
$query->setResultSetClass(__CLASS__);
}

echo '[';
foreach ($query->execute()->disableCache() as $i => $object) {
Expand Down
15 changes: 15 additions & 0 deletions library/Icingadb/Data/VolatileCsvResults.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

/* Icinga DB Web | (c) 2024 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Icingadb\Data;

use Icinga\Module\Icingadb\Redis\VolatileStateResults;

/**
* @internal This class is supposed to be used by {@see CsvResultSet::stream()} only.
*/
final class VolatileCsvResults extends VolatileStateResults
{
use CsvResultSetUtils;
}
15 changes: 15 additions & 0 deletions library/Icingadb/Data/VolatileJsonResults.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

/* Icinga DB Web | (c) 2024 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Icingadb\Data;

use Icinga\Module\Icingadb\Redis\VolatileStateResults;

/**
* @internal This class is supposed to be used by {@see JsonResultSet::stream()} only.
*/
final class VolatileJsonResults extends VolatileStateResults
{
use JsonResultSetUtils;
}

0 comments on commit e311d8b

Please sign in to comment.