Skip to content

Commit 9331c8f

Browse files
committed
perf: Optimize deleting the list of invalid shares
And make the code a bit easier to read. Signed-off-by: Carl Schwan <carlschwan@kde.org>
1 parent a118773 commit 9331c8f

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

lib/private/Repair/RepairInvalidShares.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace OC\Repair;
99

1010
use OCP\Constants;
11+
use OCP\DB\QueryBuilder\IQueryBuilder;
1112
use OCP\IConfig;
1213
use OCP\IDBConnection;
1314
use OCP\Migration\IOutput;
@@ -67,19 +68,21 @@ private function removeSharesNonExistingParent(IOutput $output): void {
6768

6869
$deleteQuery = $this->connection->getQueryBuilder();
6970
$deleteQuery->delete('share')
70-
->where($deleteQuery->expr()->eq('parent', $deleteQuery->createParameter('parent')));
71+
->where($deleteQuery->expr()->in('parent', $deleteQuery->createParameter('parent')));
7172

72-
$deletedInLastChunk = self::CHUNK_SIZE;
73-
while ($deletedInLastChunk === self::CHUNK_SIZE) {
74-
$deletedInLastChunk = 0;
73+
do {
7574
$result = $query->executeQuery();
76-
while ($row = $result->fetch()) {
77-
$deletedInLastChunk++;
78-
$deletedEntries += $deleteQuery->setParameter('parent', (int)$row['parent'])
79-
->executeStatement();
80-
}
75+
$parents = $result->fetchFirstColumn();
8176
$result->closeCursor();
82-
}
77+
78+
if ($parents === []) {
79+
break;
80+
}
81+
82+
$deletedInLastChunk = $deleteQuery->setParameter('parent', $parents, IQueryBuilder::PARAM_INT_ARRAY)
83+
->executeStatement();
84+
$deletedEntries += $deletedInLastChunk;
85+
} while ($deletedInLastChunk === self::CHUNK_SIZE);
8386

8487
if ($deletedEntries) {
8588
$output->info('Removed ' . $deletedEntries . ' shares where the parent did not exist');

0 commit comments

Comments
 (0)