Skip to content

Commit 40c91aa

Browse files
authored
Merge pull request #47182 from nextcloud/orphan-cleanup-chunk-perf
perf: improve cleanup of tags/comments
2 parents 551ff49 + 0f9ea19 commit 40c91aa

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

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)