Skip to content

Commit 3f93896

Browse files
committed
fix(Scanner): Use time based limit for the transaction
Using the node count does not help if handling a node is slow. Signed-off-by: Louis Chmn <[email protected]>
1 parent cdc73f2 commit 3f93896

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

lib/private/Files/Utils/Scanner.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use OC\ForbiddenException;
1717
use OC\Lock\DBLockingProvider;
1818
use OCA\Files_Sharing\SharedStorage;
19+
use OCP\AppFramework\Utility\ITimeFactory;
1920
use OCP\EventDispatcher\IEventDispatcher;
2021
use OCP\Files\Events\BeforeFileScannedEvent;
2122
use OCP\Files\Events\BeforeFolderScannedEvent;
@@ -43,16 +44,14 @@
4344
*
4445
* @package OC\Files\Utils
4546
*/
46-
class Scanner extends PublicEmitter {
47+
class Scanner {
48+
private const int TRANSACTION_SECOND_TIMEOUT = 10;
49+
4750
/**
4851
* Whether to use a DB transaction
4952
*/
5053
protected bool $useTransaction;
51-
52-
/**
53-
* Number of entries scanned to commit
54-
*/
55-
protected int $entriesToCommit;
54+
protected int $transactionStartTime;
5655

5756
public function __construct(
5857
private readonly string $user,
@@ -62,6 +61,7 @@ public function __construct(
6261
private readonly SetupManager $setupManager,
6362
private readonly IUserManager $userManager,
6463
private readonly IEventDispatcher $eventDispatcher,
64+
private readonly ITimeFactory $timeFactory,
6565
) {
6666
// when DB locking is used, no DB transactions will be used
6767
$this->useTransaction = !(\OCP\Server::get(ILockingProvider::class) instanceof DBLockingProvider);
@@ -237,6 +237,7 @@ public function scan(string $dir = '', $recursive = \OC\Files\Cache\Scanner::SCA
237237
}
238238

239239
if ($this->useTransaction) {
240+
$this->transactionStartTime = $this->timeFactory->getTime();
240241
$this->db->beginTransaction();
241242
}
242243
try {
@@ -273,16 +274,17 @@ private function triggerPropagator(IStorage $storage, $internalPath) {
273274

274275
private function postProcessEntry(IStorage $storage, $internalPath) {
275276
$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-
}
277+
278+
if (
279+
$this->useTransaction
280+
&& $this->transactionStartTime + self::TRANSACTION_SECOND_TIMEOUT >= $this->timeFactory->getTime()
281+
) {
282+
$propagator = $storage->getPropagator();
283+
$this->db->commit();
284+
$propagator->commitBatch();
285+
$this->db->beginTransaction();
286+
$propagator->beginBatch();
287+
$this->transactionStartTime = $this->timeFactory->getTime();
286288
}
287289
}
288290
}

0 commit comments

Comments
 (0)