Skip to content

Commit 3217a29

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

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;
@@ -45,17 +44,6 @@
4544
* @package OC\Files\Utils
4645
*/
4746
class Scanner extends PublicEmitter {
48-
public const MAX_ENTRIES_TO_COMMIT = 10000;
49-
50-
/**
51-
* Whether to use a DB transaction
52-
*/
53-
protected bool $useTransaction;
54-
55-
/**
56-
* Number of entries scanned to commit
57-
*/
58-
protected int $entriesToCommit = 0;
5947

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

217204
$scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage): void {
218-
$this->postProcessEntry($storage, $path);
205+
$this->triggerPropagator($storage, $path);
219206
$this->eventDispatcher->dispatchTyped(new NodeRemovedFromCache($storage, $path));
220207
});
221208
$scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage): void {
222-
$this->postProcessEntry($storage, $path);
209+
$this->triggerPropagator($storage, $path);
223210
$this->eventDispatcher->dispatchTyped(new FileCacheUpdated($storage, $path));
224211
});
225212
$scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path, $storageId, $data, $fileId) use ($storage): void {
226-
$this->postProcessEntry($storage, $path);
213+
$this->triggerPropagator($storage, $path);
227214
if ($fileId) {
228215
$this->eventDispatcher->dispatchTyped(new FileCacheUpdated($storage, $path));
229216
} else {
@@ -235,9 +222,6 @@ public function scan(string $dir = '', $recursive = \OC\Files\Cache\Scanner::SCA
235222
throw new NotFoundException($dir);
236223
}
237224

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

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

0 commit comments

Comments
 (0)