[Pkg-owncloud-commits] [owncloud] 21/107: Deduplicate queued trashbin expire jobs

David Prévot taffit at moszumanska.debian.org
Thu Dec 17 19:40:32 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit 36d9328afc8e9191d61f8c271d1225128e983175
Author: Morris Jobke <hey at morrisjobke.de>
Date:   Fri Nov 27 14:01:03 2015 +0100

    Deduplicate queued trashbin expire jobs
    
    * fixes #20425
    * this removes the argument trashbin size from the expire job - it is now
      calculated in the expire job
    * the queue now detects properly that the job is already queue and doesn't
      add it again
---
 apps/files_trashbin/command/expire.php           | 11 ++---------
 apps/files_trashbin/lib/trashbin.php             | 25 +++++++++---------------
 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 f34c63b..cb4e803 100644
--- a/apps/files_trashbin/command/expire.php
+++ b/apps/files_trashbin/command/expire.php
@@ -37,17 +37,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() {
@@ -59,7 +52,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 839a47a..64f3506 100644
--- a/apps/files_trashbin/lib/trashbin.php
+++ b/apps/files_trashbin/lib/trashbin.php
@@ -176,7 +176,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);
 
 		$ownerView = new \OC\Files\View('/' . $owner);
@@ -197,8 +196,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;
 
@@ -228,7 +225,6 @@ class Trashbin {
 		$ownerView->getUpdater()->rename('/files/' . $ownerPath, $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, $owner));
 			if (!$result) {
@@ -237,7 +233,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($filename, $owner, $ownerPath, $timestamp);
+			self::retainVersions($filename, $owner, $ownerPath, $timestamp);
 
 			// if owner !== user we need to also add a copy to the owners trash
 			if ($user !== $owner) {
@@ -245,14 +241,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;
@@ -618,17 +611,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;
 
@@ -644,15 +637,15 @@ 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
 		$application = new Application();
 		$expiration = $application->getContainer()->query('Expiration');
 		if ($expiration->isEnabled()) {
-			\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 a6a8a6d..0d457db 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);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list