Deduplicate version expire jobs
* versionSize is calculated anyway in the expire job - > dropped * offset/neededSpace was needed for expiry before the file is moved to the versions -> now this is included already in the currently used space because the expiry job is defered to a point in time after the version creation * fixes #21108
This commit is contained in:
parent
75c3d64635
commit
fb87441fd9
|
@ -34,16 +34,6 @@ class Expire implements ICommand {
|
||||||
*/
|
*/
|
||||||
private $fileName;
|
private $fileName;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int|null
|
|
||||||
*/
|
|
||||||
private $versionsSize;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
private $neededSpace = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
@ -52,14 +42,10 @@ class Expire implements ICommand {
|
||||||
/**
|
/**
|
||||||
* @param string $user
|
* @param string $user
|
||||||
* @param string $fileName
|
* @param string $fileName
|
||||||
* @param int|null $versionsSize
|
|
||||||
* @param int $neededSpace
|
|
||||||
*/
|
*/
|
||||||
function __construct($user, $fileName, $versionsSize = null, $neededSpace = 0) {
|
function __construct($user, $fileName) {
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
$this->fileName = $fileName;
|
$this->fileName = $fileName;
|
||||||
$this->versionsSize = $versionsSize;
|
|
||||||
$this->neededSpace = $neededSpace;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,7 +57,7 @@ class Expire implements ICommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
\OC_Util::setupFS($this->user);
|
\OC_Util::setupFS($this->user);
|
||||||
Storage::expire($this->fileName, $this->versionsSize, $this->neededSpace);
|
Storage::expire($this->fileName);
|
||||||
\OC_Util::tearDownFS();
|
\OC_Util::tearDownFS();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,14 +168,7 @@ class Storage {
|
||||||
// create all parent folders
|
// create all parent folders
|
||||||
self::createMissingDirectories($filename, $users_view);
|
self::createMissingDirectories($filename, $users_view);
|
||||||
|
|
||||||
$versionsSize = self::getVersionsSize($uid);
|
self::scheduleExpire($uid, $filename);
|
||||||
|
|
||||||
// assumption: we need filesize($filename) for the new version +
|
|
||||||
// some more free space for the modified file which might be
|
|
||||||
// 1.5 times as large as the current version -> 2.5
|
|
||||||
$neededSpace = $files_view->filesize($filename) * 2.5;
|
|
||||||
|
|
||||||
self::scheduleExpire($uid, $filename, $versionsSize, $neededSpace);
|
|
||||||
|
|
||||||
// store a new version of a file
|
// store a new version of a file
|
||||||
$mtime = $users_view->filemtime('files/' . $filename);
|
$mtime = $users_view->filemtime('files/' . $filename);
|
||||||
|
@ -634,14 +627,12 @@ class Storage {
|
||||||
*
|
*
|
||||||
* @param string $uid owner of the file
|
* @param string $uid owner of the file
|
||||||
* @param string $fileName file/folder for which to schedule expiration
|
* @param string $fileName file/folder for which to schedule expiration
|
||||||
* @param int|null $versionsSize current versions size
|
|
||||||
* @param int $neededSpace requested versions size
|
|
||||||
*/
|
*/
|
||||||
private static function scheduleExpire($uid, $fileName, $versionsSize = null, $neededSpace = 0) {
|
private static function scheduleExpire($uid, $fileName) {
|
||||||
// let the admin disable auto expire
|
// let the admin disable auto expire
|
||||||
$expiration = self::getExpiration();
|
$expiration = self::getExpiration();
|
||||||
if ($expiration->isEnabled()) {
|
if ($expiration->isEnabled()) {
|
||||||
$command = new Expire($uid, $fileName, $versionsSize, $neededSpace);
|
$command = new Expire($uid, $fileName);
|
||||||
\OC::$server->getCommandBus()->push($command);
|
\OC::$server->getCommandBus()->push($command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -650,11 +641,9 @@ class Storage {
|
||||||
* Expire versions which exceed the quota
|
* Expire versions which exceed the quota
|
||||||
*
|
*
|
||||||
* @param string $filename
|
* @param string $filename
|
||||||
* @param int|null $versionsSize
|
|
||||||
* @param int $offset
|
|
||||||
* @return bool|int|null
|
* @return bool|int|null
|
||||||
*/
|
*/
|
||||||
public static function expire($filename, $versionsSize = null, $offset = 0) {
|
public static function expire($filename) {
|
||||||
$config = \OC::$server->getConfig();
|
$config = \OC::$server->getConfig();
|
||||||
$expiration = self::getExpiration();
|
$expiration = self::getExpiration();
|
||||||
|
|
||||||
|
@ -680,9 +669,7 @@ class Storage {
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure that we have the current size of the version history
|
// make sure that we have the current size of the version history
|
||||||
if ( $versionsSize === null ) {
|
|
||||||
$versionsSize = self::getVersionsSize($uid);
|
$versionsSize = self::getVersionsSize($uid);
|
||||||
}
|
|
||||||
|
|
||||||
// calculate available space for version history
|
// calculate available space for version history
|
||||||
// subtract size of files and current versions size from quota
|
// subtract size of files and current versions size from quota
|
||||||
|
@ -692,12 +679,12 @@ class Storage {
|
||||||
$rootInfo = $files_view->getFileInfo('/', false);
|
$rootInfo = $files_view->getFileInfo('/', false);
|
||||||
$free = $quota - $rootInfo['size']; // remaining free space for user
|
$free = $quota - $rootInfo['size']; // remaining free space for user
|
||||||
if ($free > 0) {
|
if ($free > 0) {
|
||||||
$availableSpace = ($free * self::DEFAULTMAXSIZE / 100) - ($versionsSize + $offset); // how much space can be used for versions
|
$availableSpace = ($free * self::DEFAULTMAXSIZE / 100) - $versionsSize; // how much space can be used for versions
|
||||||
} else {
|
} else {
|
||||||
$availableSpace = $free - $versionsSize - $offset;
|
$availableSpace = $free - $versionsSize;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$availableSpace = $quota - $offset;
|
$availableSpace = $quota;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$availableSpace = PHP_INT_MAX;
|
$availableSpace = PHP_INT_MAX;
|
||||||
|
|
Loading…
Reference in New Issue