Skip to content

Commit d3defd2

Browse files
committed
perf: improve cleanup of tags/comments
delete entire chunk at once instead of one-by-one Signed-off-by: Robin Appelman <[email protected]>
1 parent e49c55d commit d3defd2

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

apps/files/lib/BackgroundJob/DeleteOrphanedItems.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,15 @@ protected function cleanUp($table, $idCol, $typeCol) {
6666

6767
$deleteQuery = $this->connection->getQueryBuilder();
6868
$deleteQuery->delete($table)
69-
->where($deleteQuery->expr()->eq($idCol, $deleteQuery->createParameter('objectid')));
69+
->where($deleteQuery->expr()->in($idCol, $deleteQuery->createParameter('objectid')));
7070

7171
$deletedInLastChunk = self::CHUNK_SIZE;
7272
while ($deletedInLastChunk === self::CHUNK_SIZE) {
73-
$result = $query->execute();
74-
$deletedInLastChunk = 0;
75-
while ($row = $result->fetch()) {
76-
$deletedInLastChunk++;
77-
$deletedEntries += $deleteQuery->setParameter('objectid', (int) $row[$idCol])
78-
->execute();
79-
}
80-
$result->closeCursor();
73+
$chunk = $query->executeQuery()->fetchAll(\PDO::FETCH_COLUMN);
74+
$deletedInLastChunk = count($chunk);
75+
76+
$deleteQuery->setParameter('objectid', $chunk, IQueryBuilder::PARAM_INT_ARRAY);
77+
$deletedEntries += $deleteQuery->executeStatement();
8178
}
8279

8380
return $deletedEntries;

0 commit comments

Comments
 (0)