perf: improve cleanup of tags/comments

delete entire chunk at once instead of one-by-one

Signed-off-by: Robin Appelman <robin@icewind.nl>
pull/47182/head
Robin Appelman 9 months ago
parent 15550de8ce
commit 0f9ea1992c
  1. 15
      apps/files/lib/BackgroundJob/DeleteOrphanedItems.php

@ -66,18 +66,15 @@ class DeleteOrphanedItems extends TimedJob {
$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;

Loading…
Cancel
Save