aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouis Chemineau <louis@chmn.me>2025-03-26 21:01:47 +0100
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2025-03-31 11:01:00 +0000
commit3e45b3b4185cc0f58d6095fabead18013bbe4b00 (patch)
treea9b51760db72eee699f83a7de8713a5a5e44e95d
parent822761af707eeb518757eca4075be56748cca884 (diff)
downloadnextcloud-server-backport/51600/stable30.tar.gz
nextcloud-server-backport/51600/stable30.zip
feat: Limit trash expire job to 30 minutesbackport/51600/stable30
And pick up where it left off, leveraging getSeenUsers. Signed-off-by: Louis Chemineau <louis@chmn.me> [skip ci]
-rw-r--r--apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php22
-rw-r--r--apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php27
2 files changed, 28 insertions, 21 deletions
diff --git a/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php
index e458039bf4f..918f96990c9 100644
--- a/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php
+++ b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php
@@ -11,8 +11,7 @@ use OCA\Files_Trashbin\Helper;
use OCA\Files_Trashbin\Trashbin;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
-use OCP\IConfig;
-use OCP\IUser;
+use OCP\IAppConfig;
use OCP\IUserManager;
class ExpireTrash extends TimedJob {
@@ -35,12 +34,8 @@ class ExpireTrash extends TimedJob {
$this->expiration = $expiration;
}
- /**
- * @param $argument
- * @throws \Exception
- */
protected function run($argument) {
- $backgroundJob = $this->config->getAppValue('files_trashbin', 'background_job_expire_trash', 'yes');
+ $backgroundJob = $this->appConfig->getValueString('files_trashbin', 'background_job_expire_trash', 'yes');
if ($backgroundJob === 'no') {
return;
}
@@ -53,12 +48,21 @@ class ExpireTrash extends TimedJob {
$this->userManager->callForSeenUsers(function (IUser $user) {
$uid = $user->getUID();
if (!$this->setupFS($uid)) {
- return;
+ continue;
}
$dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
Trashbin::deleteExpiredFiles($dirContent, $uid);
- });
+ $offset++;
+
+ if ($stopTime < time()) {
+ $this->appConfig->setValueInt('files_trashbin', 'background_job_expire_trash_offset', $offset);
+ \OC_Util::tearDownFS();
+ return;
+ }
+ }
+
+ $this->appConfig->setValueInt('files_trashbin', 'background_job_expire_trash_offset', 0);
\OC_Util::tearDownFS();
}
diff --git a/apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php b/apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php
index b172f1f2715..82977068983 100644
--- a/apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php
+++ b/apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php
@@ -11,31 +11,31 @@ use OCA\Files_Trashbin\BackgroundJob\ExpireTrash;
use OCA\Files_Trashbin\Expiration;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
-use OCP\IConfig;
+use OCP\IAppConfig;
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class ExpireTrashTest extends TestCase {
- /** @var IConfig|MockObject */
- private $config;
+ /** @var IAppConfig&MockObject */
+ private $appConfig;
- /** @var IUserManager|MockObject */
+ /** @var IUserManager&MockObject */
private $userManager;
- /** @var Expiration|MockObject */
+ /** @var Expiration&MockObject */
private $expiration;
- /** @var IJobList|MockObject */
+ /** @var IJobList&MockObject */
private $jobList;
- /** @var ITimeFactory|MockObject */
+ /** @var ITimeFactory&MockObject */
private $time;
protected function setUp(): void {
parent::setUp();
- $this->config = $this->createMock(IConfig::class);
+ $this->appConfig = $this->createMock(IAppConfig::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->expiration = $this->createMock(Expiration::class);
$this->jobList = $this->createMock(IJobList::class);
@@ -51,22 +51,25 @@ class ExpireTrashTest extends TestCase {
}
public function testConstructAndRun(): void {
- $this->config->method('getAppValue')
+ $this->appConfig->method('getValueString')
->with('files_trashbin', 'background_job_expire_trash', 'yes')
->willReturn('yes');
+ $this->appConfig->method('getValueInt')
+ ->with('files_trashbin', 'background_job_expire_trash_offset', 0)
+ ->willReturn(0);
- $job = new ExpireTrash($this->config, $this->userManager, $this->expiration, $this->time);
+ $job = new ExpireTrash($this->appConfig, $this->userManager, $this->expiration, $this->time);
$job->start($this->jobList);
}
public function testBackgroundJobDeactivated(): void {
- $this->config->method('getAppValue')
+ $this->appConfig->method('getValueString')
->with('files_trashbin', 'background_job_expire_trash', 'yes')
->willReturn('no');
$this->expiration->expects($this->never())
->method('getMaxAgeAsTimestamp');
- $job = new ExpireTrash($this->config, $this->userManager, $this->expiration, $this->time);
+ $job = new ExpireTrash($this->appConfig, $this->userManager, $this->expiration, $this->time);
$job->start($this->jobList);
}
}