From d3defd282c669aeb7cea5366b6685b816e28a9ec Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 12 Aug 2024 16:13:58 +0200 Subject: [PATCH] perf: improve cleanup of tags/comments delete entire chunk at once instead of one-by-one Signed-off-by: Robin Appelman --- .../lib/BackgroundJob/DeleteOrphanedItems.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/apps/files/lib/BackgroundJob/DeleteOrphanedItems.php b/apps/files/lib/BackgroundJob/DeleteOrphanedItems.php index a4b2a6cf3f809..0d6a632db1ac5 100644 --- a/apps/files/lib/BackgroundJob/DeleteOrphanedItems.php +++ b/apps/files/lib/BackgroundJob/DeleteOrphanedItems.php @@ -66,18 +66,15 @@ protected function cleanUp($table, $idCol, $typeCol) { $deleteQuery = $this->connection->getQueryBuilder(); $deleteQuery->delete($table) - ->where($deleteQuery->expr()->eq($idCol, $deleteQuery->createParameter('objectid'))); + ->where($deleteQuery->expr()->in($idCol, $deleteQuery->createParameter('objectid'))); $deletedInLastChunk = self::CHUNK_SIZE; while ($deletedInLastChunk === self::CHUNK_SIZE) { - $result = $query->execute(); - $deletedInLastChunk = 0; - while ($row = $result->fetch()) { - $deletedInLastChunk++; - $deletedEntries += $deleteQuery->setParameter('objectid', (int) $row[$idCol]) - ->execute(); - } - $result->closeCursor(); + $chunk = $query->executeQuery()->fetchAll(\PDO::FETCH_COLUMN); + $deletedInLastChunk = count($chunk); + + $deleteQuery->setParameter('objectid', $chunk, IQueryBuilder::PARAM_INT_ARRAY); + $deletedEntries += $deleteQuery->executeStatement(); } return $deletedEntries;