Skip to content

Commit

Permalink
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>

[skip ci]
  • Loading branch information
ChristophWurst authored and solracsf committed May 29, 2024
1 parent d125aa3 commit 64469ef
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
26 changes: 24 additions & 2 deletions apps/files_sharing/lib/DeleteOrphanedSharesJob.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
Expand All @@ -24,21 +27,40 @@
*/
namespace OCA\Files_Sharing;

use OCP\AppFramework\Db\TTransactional;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;

/**
* Delete all share entries that have no matching entries in the file cache table.
*/
class DeleteOrphanedSharesJob extends TimedJob {

use TTransactional;

private const CHUNK_SIZE = 1000;

private const INTERVAL = 24 * 60 * 60; // 1 day

private IDBConnection $db;

private LoggerInterface $logger;

/**
* sets the correct interval for this timed job
*/
public function __construct(ITimeFactory $time) {
public function __construct(
ITimeFactory $time,
IDBConnection $db,
LoggerInterface $logger
) {
parent::__construct($time);

$this->setInterval(24 * 60 * 60); // 1 day
$this->db = $db;

$this->setInterval(self::INTERVAL); // 1 day
$this->setTimeSensitivity(self::TIME_INSENSITIVE);
$this->logger = $logger;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions apps/files_sharing/tests/DeleteOrphanedSharesJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
namespace OCA\Files_Sharing\Tests;

use OCA\Files_Sharing\DeleteOrphanedSharesJob;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Share\IShare;

/**
Expand Down Expand Up @@ -94,7 +93,7 @@ protected function setUp(): void {

\OC::registerShareHooks(\OC::$server->getSystemConfig());

$this->job = new DeleteOrphanedSharesJob(\OCP\Server::get(ITimeFactory::class));
$this->job = \OCP\Server::get(DeleteOrphanedSharesJob::class);
}

protected function tearDown(): void {
Expand Down

0 comments on commit 64469ef

Please sign in to comment.