diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-02-10 17:26:11 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-02-10 17:26:11 +0100 |
commit | 6ffb83ae19e423ab894670cef116350ca86f331b (patch) | |
tree | 72466ee0c53e0e901dfddd47452fbcd8fa7e824c /lib | |
parent | 39e6a1897b82b3433b5ed6437f14e2739ba26d32 (diff) | |
parent | 0ebb2050102190b1186c7338a84f86bd6f3f9d43 (diff) | |
download | nextcloud-server-6ffb83ae19e423ab894670cef116350ca86f331b.tar.gz nextcloud-server-6ffb83ae19e423ab894670cef116350ca86f331b.zip |
Merge pull request #22269 from owncloud/issue-22243-avoid-deadlock-with-lots-of-entries-to-cleanup
Chunk the cleanup queries to make sure they don't time out
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/repair/repairinvalidshares.php | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/lib/private/repair/repairinvalidshares.php b/lib/private/repair/repairinvalidshares.php index ee8b23906e5..beef5e37798 100644 --- a/lib/private/repair/repairinvalidshares.php +++ b/lib/private/repair/repairinvalidshares.php @@ -30,6 +30,8 @@ use OC\Hooks\BasicEmitter; */ class RepairInvalidShares extends BasicEmitter implements \OC\RepairStep { + const CHUNK_SIZE = 200; + /** * @var \OCP\IConfig */ @@ -83,18 +85,24 @@ class RepairInvalidShares extends BasicEmitter implements \OC\RepairStep { ->where($query->expr()->isNotNull('s1.parent')) ->andWhere($query->expr()->isNull('s2.id')) ->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id')) - ->groupBy('s1.parent'); + ->groupBy('s1.parent') + ->setMaxResults(self::CHUNK_SIZE); $deleteQuery = $this->connection->getQueryBuilder(); $deleteQuery->delete('share') - ->where($query->expr()->eq('parent', $deleteQuery->createParameter('parent'))); - - $result = $query->execute(); - while ($row = $result->fetch()) { - $deletedEntries += $deleteQuery->setParameter('parent', (int) $row['parent']) - ->execute(); + ->where($deleteQuery->expr()->eq('parent', $deleteQuery->createParameter('parent'))); + + $deletedInLastChunk = self::CHUNK_SIZE; + while ($deletedInLastChunk === self::CHUNK_SIZE) { + $deletedInLastChunk = 0; + $result = $query->execute(); + while ($row = $result->fetch()) { + $deletedInLastChunk++; + $deletedEntries += $deleteQuery->setParameter('parent', (int) $row['parent']) + ->execute(); + } + $result->closeCursor(); } - $result->closeCursor(); if ($deletedEntries) { $this->emit('\OC\Repair', 'info', array('Removed ' . $deletedEntries . ' shares where the parent did not exist')); |