From cfd2ebade434bab8c9b0965e5818217d0bfb52c0 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 22 Oct 2022 13:13:06 +0200 Subject: [PATCH] Improve the performance of the attachment export The query caused a full table scan, slowing down each cycle dramatically. --- .../system/exporter/IPB3xExporter.class.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/files/lib/system/exporter/IPB3xExporter.class.php b/files/lib/system/exporter/IPB3xExporter.class.php index b1c9821..cbf9707 100644 --- a/files/lib/system/exporter/IPB3xExporter.class.php +++ b/files/lib/system/exporter/IPB3xExporter.class.php @@ -1175,15 +1175,7 @@ class IPB3xExporter extends AbstractExporter */ private function countAttachments($type) { - $sql = "SELECT COUNT(*) AS count - FROM " . $this->databasePrefix . "attachments - WHERE attach_rel_module = ? - AND attach_rel_id > ?"; - $statement = $this->database->prepareStatement($sql); - $statement->execute([$type, 0]); - $row = $statement->fetchArray(); - - return $row['count']; + return $this->__getMaxID($this->databasePrefix . "attachments", 'attach_id'); } /** @@ -1200,9 +1192,15 @@ class IPB3xExporter extends AbstractExporter FROM " . $this->databasePrefix . "attachments WHERE attach_rel_module = ? AND attach_rel_id > ? + AND attach_id BETWEEN ? AND ? ORDER BY attach_id DESC"; $statement = $this->database->prepareStatement($sql, $limit, $offset); - $statement->execute([$type, 0]); + $statement->execute([ + $type, + 0, + $offset + 1, + $offset + $limit, + ]); while ($row = $statement->fetchArray()) { $fileLocation = $this->fileSystemPath . 'uploads/' . $row['attach_location']; -- 2.20.1