Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable26] fix(sharing): Avoid (dead)locking during orphan deletion #44008

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
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