From e311d8b9a9b6d4639c9bb3b9b02e8792e5126771 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 20 Mar 2024 15:00:03 +0100 Subject: [PATCH] Use separate result sets when exporting hosts/services --- library/Icingadb/Data/CsvResultSet.php | 4 ++-- library/Icingadb/Data/CsvResultSetUtils.php | 8 +++++++- library/Icingadb/Data/JsonResultSet.php | 4 ++-- library/Icingadb/Data/JsonResultSetUtils.php | 8 +++++++- library/Icingadb/Data/VolatileCsvResults.php | 15 +++++++++++++++ library/Icingadb/Data/VolatileJsonResults.php | 15 +++++++++++++++ 6 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 library/Icingadb/Data/VolatileCsvResults.php create mode 100644 library/Icingadb/Data/VolatileJsonResults.php diff --git a/library/Icingadb/Data/CsvResultSet.php b/library/Icingadb/Data/CsvResultSet.php index 1e6d7c546..d65364e9a 100644 --- a/library/Icingadb/Data/CsvResultSet.php +++ b/library/Icingadb/Data/CsvResultSet.php @@ -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; } diff --git a/library/Icingadb/Data/CsvResultSetUtils.php b/library/Icingadb/Data/CsvResultSetUtils.php index 42b25dfa5..254341af1 100644 --- a/library/Icingadb/Data/CsvResultSetUtils.php +++ b/library/Icingadb/Data/CsvResultSetUtils.php @@ -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; @@ -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) { diff --git a/library/Icingadb/Data/JsonResultSet.php b/library/Icingadb/Data/JsonResultSet.php index e5507bbf0..715437a92 100644 --- a/library/Icingadb/Data/JsonResultSet.php +++ b/library/Icingadb/Data/JsonResultSet.php @@ -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; } diff --git a/library/Icingadb/Data/JsonResultSetUtils.php b/library/Icingadb/Data/JsonResultSetUtils.php index 23d04913e..b314b1e69 100644 --- a/library/Icingadb/Data/JsonResultSetUtils.php +++ b/library/Icingadb/Data/JsonResultSetUtils.php @@ -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; @@ -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) { diff --git a/library/Icingadb/Data/VolatileCsvResults.php b/library/Icingadb/Data/VolatileCsvResults.php new file mode 100644 index 000000000..7d9f8ab35 --- /dev/null +++ b/library/Icingadb/Data/VolatileCsvResults.php @@ -0,0 +1,15 @@ +