diff --git a/library/Icingadb/Data/CsvResultSetUtils.php b/library/Icingadb/Data/CsvResultSetUtils.php index 254341af1..61995d3a2 100644 --- a/library/Icingadb/Data/CsvResultSetUtils.php +++ b/library/Icingadb/Data/CsvResultSetUtils.php @@ -73,15 +73,33 @@ public static function stream(Query $query): void $query->setResultSetClass(__CLASS__); } - foreach ($query->execute()->disableCache() as $i => $keysAndValues) { - if ($i === 0) { - echo implode(',', array_keys($keysAndValues)); - } + if ($query->hasLimit()) { + // Custom limits should still apply + $query->peekAhead(false); + $offset = $query->getOffset(); + } else { + $query->limit(1000); + $query->peekAhead(); + $offset = 0; + } - echo "\r\n"; + do { + $query->offset($offset); + $result = $query->execute()->disableCache(); + foreach ($result as $i => $keysAndValues) { + if ($i === 0) { + echo implode(',', array_keys($keysAndValues)); + } - echo implode(',', array_values($keysAndValues)); - } + echo "\r\n"; + + echo implode(',', array_values($keysAndValues)); + + JsonResultSet::giveMeMoreTime(); + } + + $offset += 1000; + } while ($result->hasMore()); exit; }