Skip to content

Commit

Permalink
fixup! fix(sharing): Avoid (dead)locking during orphan deletion
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
  • Loading branch information
ChristophWurst committed Feb 12, 2024
1 parent b1488e3 commit f0743d5
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions apps/files_sharing/lib/DeleteOrphanedSharesJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,12 @@ class DeleteOrphanedSharesJob extends TimedJob {

private const CHUNK_SIZE = 1000;

private const INTERVAL = 5 * 60;

private IDBConnection $db;

private LoggerInterface $logger;

/**
* Default interval in minutes
*
* @var int $defaultIntervalMin
**/
protected $defaultIntervalMin = 15;

/**
* sets the correct interval for this timed job
*/
Expand All @@ -66,7 +61,7 @@ public function __construct(ITimeFactory $time,

$this->db = $db;

$this->interval = $this->defaultIntervalMin * 60;
$this->setInterval(self::INTERVAL);
$this->logger = $logger;
}

Expand All @@ -90,7 +85,7 @@ public function run($argument) {

/**
* Read a chunk of orphan rows and delete them. Continue as long as the
* chunk is filled.
* chunk is filled and time before the next cron run does not run out.
*
* Note: With isolation level READ COMMITTED, the database will allow
* other transactions to delete rows between our SELECT and DELETE. In
Expand All @@ -101,6 +96,7 @@ public function run($argument) {
* could be combined into one single DELETE with join or sub query, but
* that has shown to (dead)lock often.
*/
$cutOff = $this->time->getTime() + self::INTERVAL;
do {
$deleted = $this->atomic(function () use ($qbSelect, $deleteQb) {
$result = $qbSelect->executeQuery();
Expand All @@ -114,6 +110,6 @@ public function run($argument) {
]);
return $deleted;
}, $this->db);
} while ($deleted >= self::CHUNK_SIZE);
} while ($deleted >= self::CHUNK_SIZE && $this->time->getTime() <= $cutOff);
}
}

0 comments on commit f0743d5

Please sign in to comment.