Skip to content

Commit f503ff8

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

1 file changed

Lines changed: 3 additions & 37 deletions

File tree

lib/private/Files/Utils/Scanner.php

Lines changed: 3 additions & 37 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;
@@ -46,17 +45,6 @@
4645
* @package OC\Files\Utils
4746
*/
4847
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;
6048

6149
public function __construct(
6250
private readonly ?IUser $user,
@@ -212,19 +200,18 @@ public function scan(string $dir = '', $recursive = \OC\Files\Cache\Scanner::SCA
212200
$relativePath = $mount->getInternalPath($dir);
213201
/** @var \OC\Files\Cache\Scanner $scanner */
214202
$scanner = $storage->getScanner();
215-
$scanner->setUseTransactions(false);
216203
$this->attachListener($mount);
217204

218205
$scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage): void {
219-
$this->postProcessEntry($storage, $path);
206+
$this->triggerPropagator($storage, $path);
220207
$this->eventDispatcher->dispatchTyped(new NodeRemovedFromCache($storage, $path));
221208
});
222209
$scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage): void {
223-
$this->postProcessEntry($storage, $path);
210+
$this->triggerPropagator($storage, $path);
224211
$this->eventDispatcher->dispatchTyped(new FileCacheUpdated($storage, $path));
225212
});
226213
$scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path, $storageId, $data, $fileId) use ($storage): void {
227-
$this->postProcessEntry($storage, $path);
214+
$this->triggerPropagator($storage, $path);
228215
if ($fileId) {
229216
$this->eventDispatcher->dispatchTyped(new FileCacheUpdated($storage, $path));
230217
} else {
@@ -236,9 +223,6 @@ public function scan(string $dir = '', $recursive = \OC\Files\Cache\Scanner::SCA
236223
throw new NotFoundException($dir);
237224
}
238225

239-
if ($this->useTransaction) {
240-
$this->db->beginTransaction();
241-
}
242226
try {
243227
$propagator = $storage->getPropagator();
244228
$propagator->beginBatch();
@@ -261,28 +245,10 @@ public function scan(string $dir = '', $recursive = \OC\Files\Cache\Scanner::SCA
261245
$this->logger->error('Storage ' . $storage->getId() . ' not available', ['exception' => $e]);
262246
$this->emit('\OC\Files\Utils\Scanner', 'StorageNotAvailable', [$e]);
263247
}
264-
if ($this->useTransaction) {
265-
$this->db->commit();
266-
}
267248
}
268249
}
269250

270251
private function triggerPropagator(IStorage $storage, $internalPath) {
271252
$storage->getPropagator()->propagateChange($internalPath, time());
272253
}
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-
}
288254
}

0 commit comments

Comments
 (0)