Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(sharing): Avoid (dead)locking during orphan deletion
Signed-off-by: Christoph Wurst <[email protected]>

[skip ci]
  • Loading branch information
ChristophWurst authored and solracsf committed May 29, 2024
commit 64469efa2974aa87e54f50050e782ce348c84b4a
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