Skip to content

Commit 680ddd9

Browse files
committed
fix(Scanner): Remove high level transaction during scans
Signed-off-by: Louis Chmn <louis@chmn.me>
1 parent 72812b2 commit 680ddd9

1 file changed

Lines changed: 3 additions & 41 deletions

File tree

lib/private/Files/Utils/Scanner.php

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use OC\Files\Storage\Home;
1616
use OC\ForbiddenException;
1717
use OC\Hooks\PublicEmitter;
18-
use OC\Lock\DBLockingProvider;
1918
use OCA\Files_Sharing\SharedStorage;
2019
use OCP\EventDispatcher\IEventDispatcher;
2120
use OCP\Files\Events\BeforeFileScannedEvent;
@@ -31,9 +30,7 @@
3130
use OCP\Files\StorageNotAvailableException;
3231
use OCP\IDBConnection;
3332
use OCP\IUser;
34-
use OCP\Lock\ILockingProvider;
3533
use OCP\Lock\LockedException;
36-
use OCP\Server;
3734
use Psr\Log\LoggerInterface;
3835

3936
/**
@@ -46,17 +43,6 @@
4643
* @package OC\Files\Utils
4744
*/
4845
class Scanner extends PublicEmitter {
49-
public const MAX_ENTRIES_TO_COMMIT = 10000;
50-
51-
/**
52-
* Whether to use a DB transaction
53-
*/
54-
protected bool $useTransaction;
55-
56-
/**
57-
* Number of entries scanned to commit
58-
*/
59-
protected int $entriesToCommit = 0;
6046

6147
public function __construct(
6248
private readonly ?IUser $user,
@@ -65,8 +51,6 @@ public function __construct(
6551
protected readonly LoggerInterface $logger,
6652
private readonly SetupManager $setupManager,
6753
) {
68-
// when DB locking is used, no DB transactions will be used
69-
$this->useTransaction = !(Server::get(ILockingProvider::class) instanceof DBLockingProvider);
7054
}
7155

7256
/**
@@ -212,19 +196,18 @@ public function scan(string $dir = '', $recursive = \OC\Files\Cache\Scanner::SCA
212196
$relativePath = $mount->getInternalPath($dir);
213197
/** @var \OC\Files\Cache\Scanner $scanner */
214198
$scanner = $storage->getScanner();
215-
$scanner->setUseTransactions(false);
216199
$this->attachListener($mount);
217200

218201
$scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage): void {
219-
$this->postProcessEntry($storage, $path);
202+
$this->triggerPropagator($storage, $path);
220203
$this->eventDispatcher->dispatchTyped(new NodeRemovedFromCache($storage, $path));
221204
});
222205
$scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage): void {
223-
$this->postProcessEntry($storage, $path);
206+
$this->triggerPropagator($storage, $path);
224207
$this->eventDispatcher->dispatchTyped(new FileCacheUpdated($storage, $path));
225208
});
226209
$scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path, $storageId, $data, $fileId) use ($storage): void {
227-
$this->postProcessEntry($storage, $path);
210+
$this->triggerPropagator($storage, $path);
228211
if ($fileId) {
229212
$this->eventDispatcher->dispatchTyped(new FileCacheUpdated($storage, $path));
230213
} else {
@@ -236,9 +219,6 @@ public function scan(string $dir = '', $recursive = \OC\Files\Cache\Scanner::SCA
236219
throw new NotFoundException($dir);
237220
}
238221

239-
if ($this->useTransaction) {
240-
$this->db->beginTransaction();
241-
}
242222
try {
243223
$propagator = $storage->getPropagator();
244224
$propagator->beginBatch();
@@ -261,28 +241,10 @@ public function scan(string $dir = '', $recursive = \OC\Files\Cache\Scanner::SCA
261241
$this->logger->error('Storage ' . $storage->getId() . ' not available', ['exception' => $e]);
262242
$this->emit('\OC\Files\Utils\Scanner', 'StorageNotAvailable', [$e]);
263243
}
264-
if ($this->useTransaction) {
265-
$this->db->commit();
266-
}
267244
}
268245
}
269246

270247
private function triggerPropagator(IStorage $storage, $internalPath) {
271248
$storage->getPropagator()->propagateChange($internalPath, time());
272249
}
273-
274-
private function postProcessEntry(IStorage $storage, $internalPath) {
275-
$this->triggerPropagator($storage, $internalPath);
276-
if ($this->useTransaction) {
277-
$this->entriesToCommit++;
278-
if ($this->entriesToCommit >= self::MAX_ENTRIES_TO_COMMIT) {
279-
$propagator = $storage->getPropagator();
280-
$this->entriesToCommit = 0;
281-
$this->db->commit();
282-
$propagator->commitBatch();
283-
$this->db->beginTransaction();
284-
$propagator->beginBatch();
285-
}
286-
}
287-
}
288250
}

0 commit comments

Comments
 (0)