diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-12-04 17:45:24 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-12-04 17:45:24 +0100 |
commit | 563f0c8a81fb8dc37fb70a6fc23c01224ec496cf (patch) | |
tree | 3fb7cb338ab5c2a524684bea98495448701b6af5 | |
parent | bab3fcb134d0da612256db0206365e252ad3a71d (diff) | |
parent | df6344211ee012be4dba30cf2cf54caaca37d95c (diff) | |
download | nextcloud-server-563f0c8a81fb8dc37fb70a6fc23c01224ec496cf.tar.gz nextcloud-server-563f0c8a81fb8dc37fb70a6fc23c01224ec496cf.zip |
Merge pull request #20795 from owncloud/stable8.1-backport-20790
[stable8.1] Deduplicate queued trashbin expire jobs
-rw-r--r-- | apps/files_trashbin/command/expire.php | 11 | ||||
-rw-r--r-- | apps/files_trashbin/lib/trashbin.php | 25 | ||||
-rw-r--r-- | apps/files_trashbin/tests/command/expiretest.php | 2 |
3 files changed, 12 insertions, 26 deletions
diff --git a/apps/files_trashbin/command/expire.php b/apps/files_trashbin/command/expire.php index 89b949bbcdf..b6eb2a74e0b 100644 --- a/apps/files_trashbin/command/expire.php +++ b/apps/files_trashbin/command/expire.php @@ -38,17 +38,10 @@ class Expire implements ICommand { private $user; /** - * @var int - */ - private $trashBinSize; - - /** * @param string $user - * @param int $trashBinSize */ - function __construct($user, $trashBinSize) { + function __construct($user) { $this->user = $user; - $this->trashBinSize = $trashBinSize; } public function handle() { @@ -60,7 +53,7 @@ class Expire implements ICommand { \OC_Util::tearDownFS(); \OC_Util::setupFS($this->user); - Trashbin::expire($this->trashBinSize, $this->user); + Trashbin::expire($this->user); \OC_Util::tearDownFS(); } } diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php index 668a3c51537..0f556a0aaf7 100644 --- a/apps/files_trashbin/lib/trashbin.php +++ b/apps/files_trashbin/lib/trashbin.php @@ -175,7 +175,6 @@ class Trashbin { // get the user for which the filesystem is setup $root = Filesystem::getRoot(); list(, $user) = explode('/', $root); - $size = 0; list($owner, $ownerPath) = self::getUidAndFilename($file_path); $view = new \OC\Files\View('/' . $user); @@ -196,8 +195,6 @@ class Trashbin { $location = $path_parts['dirname']; $timestamp = time(); - $userTrashSize = self::getTrashbinSize($user); - // disable proxy to prevent recursive calls $trashPath = '/files_trashbin/files/' . $filename . '.d' . $timestamp; @@ -227,7 +224,6 @@ class Trashbin { $view->getUpdater()->rename('/files/' . $file_path, $trashPath); if ($sizeOfAddedFiles !== false) { - $size = $sizeOfAddedFiles; $query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`user`) VALUES (?,?,?,?)"); $result = $query->execute(array($filename, $timestamp, $location, $user)); if (!$result) { @@ -236,7 +232,7 @@ class Trashbin { \OCP\Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_moveToTrash', array('filePath' => \OC\Files\Filesystem::normalizePath($file_path), 'trashPath' => \OC\Files\Filesystem::normalizePath($filename . '.d' . $timestamp))); - $size += self::retainVersions($file_path, $filename, $owner, $ownerPath, $timestamp); + self::retainVersions($file_path, $filename, $owner, $ownerPath, $timestamp); // if owner !== user we need to also add a copy to the owners trash if ($user !== $owner) { @@ -244,14 +240,11 @@ class Trashbin { } } - $userTrashSize += $size; - self::scheduleExpire($userTrashSize, $user); + self::scheduleExpire($user); // if owner !== user we also need to update the owners trash size if ($owner !== $user) { - $ownerTrashSize = self::getTrashbinSize($owner); - $ownerTrashSize += $size; - self::scheduleExpire($ownerTrashSize, $owner); + self::scheduleExpire($owner); } return ($sizeOfAddedFiles === false) ? false : true; @@ -617,17 +610,17 @@ class Trashbin { $freeSpace = self::calculateFreeSpace($size, $user); if ($freeSpace < 0) { - self::scheduleExpire($size, $user); + self::scheduleExpire($user); } } /** * clean up the trash bin * - * @param int $trashBinSize current size of the trash bin * @param string $user */ - public static function expire($trashBinSize, $user) { + public static function expire($user) { + $trashBinSize = self::getTrashbinSize($user); $availableSpace = self::calculateFreeSpace($trashBinSize, $user); $size = 0; @@ -647,16 +640,16 @@ class Trashbin { $size += self::deleteFiles(array_slice($dirContent, $count), $user, $availableSpace); } - /**@param int $trashBinSize current size of the trash bin + /** * @param string $user */ - private static function scheduleExpire($trashBinSize, $user) { + private static function scheduleExpire($user) { // let the admin disable auto expire $autoExpire = \OC_Config::getValue('trashbin_auto_expire', true); if ($autoExpire === false) { return; } - \OC::$server->getCommandBus()->push(new Expire($user, $trashBinSize)); + \OC::$server->getCommandBus()->push(new Expire($user)); } /** diff --git a/apps/files_trashbin/tests/command/expiretest.php b/apps/files_trashbin/tests/command/expiretest.php index a6a8a6d53a8..0d457db2807 100644 --- a/apps/files_trashbin/tests/command/expiretest.php +++ b/apps/files_trashbin/tests/command/expiretest.php @@ -26,7 +26,7 @@ use Test\TestCase; class ExpireTest extends TestCase { public function testExpireNonExistingUser() { - $command = new Expire('test', 0); + $command = new Expire('test'); $command->handle(); $this->assertTrue(true); |