Skip to content

Commit

Permalink
Merge pull request #47182 from nextcloud/orphan-cleanup-chunk-perf
Browse files Browse the repository at this point in the history
perf: improve cleanup of tags/comments
  • Loading branch information
icewind1991 authored Aug 19, 2024
2 parents 551ff49 + 0f9ea19 commit 40c91aa
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions apps/files/lib/BackgroundJob/DeleteOrphanedItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 40c91aa

Please sign in to comment.