aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2024-02-01 09:31:12 +0100
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2024-03-05 21:04:12 +0000
commit7a3d794eedd859affad858ddf7351def5a600e75 (patch)
tree2d43191ddcab95c721f95df73c617d3647ee76bb
parentcce4a78519a6a6f739cc8a1fb58db5858d126c45 (diff)
downloadnextcloud-server-backport/43252/stable26.tar.gz
nextcloud-server-backport/43252/stable26.zip
fix(sharing): Avoid (dead)locking during orphan deletionbackport/43252/stable26
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at> [skip ci]
-rw-r--r--apps/files_sharing/lib/DeleteOrphanedSharesJob.php26
-rw-r--r--apps/files_sharing/tests/DeleteOrphanedSharesJobTest.php3
2 files changed, 25 insertions, 4 deletions
diff --git a/apps/files_sharing/lib/DeleteOrphanedSharesJob.php b/apps/files_sharing/lib/DeleteOrphanedSharesJob.php
index a9452cb3dcc..0763711114a 100644
--- a/apps/files_sharing/lib/DeleteOrphanedSharesJob.php
+++ b/apps/files_sharing/lib/DeleteOrphanedSharesJob.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -24,6 +27,7 @@
*/
namespace OCA\Files_Sharing;
+use OCP\AppFramework\Db\TTransactional;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
@@ -31,14 +35,32 @@ 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;
}
/**
diff --git a/apps/files_sharing/tests/DeleteOrphanedSharesJobTest.php b/apps/files_sharing/tests/DeleteOrphanedSharesJobTest.php
index 3de40215f15..0a39246e030 100644
--- a/apps/files_sharing/tests/DeleteOrphanedSharesJobTest.php
+++ b/apps/files_sharing/tests/DeleteOrphanedSharesJobTest.php
@@ -27,7 +27,6 @@
namespace OCA\Files_Sharing\Tests;
use OCA\Files_Sharing\DeleteOrphanedSharesJob;
-use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Share\IShare;
/**
@@ -94,7 +93,7 @@ class DeleteOrphanedSharesJobTest extends \Test\TestCase {
\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 {