Merge pull request #8471 from owncloud/versioning_no_longer_track_the_size
[versioning] let the file cache track the size of the versions
This commit is contained in:
commit
a2db53b928
7 changed files with 12 additions and 118 deletions
|
@ -5,6 +5,5 @@ $installedVersion=OCP\Config::getAppValue('files_trashbin', 'installed_version')
|
|||
if (version_compare($installedVersion, '0.6', '<')) {
|
||||
//size of the trash bin could be incorrect, remove it for all users to
|
||||
//enforce a recalculation during next usage.
|
||||
$query = \OC_DB::prepare('DELETE FROM `*PREFIX*files_trashsize`');
|
||||
$result = $query->execute();
|
||||
\OC_DB::dropTable('files_trashsize');
|
||||
}
|
||||
|
|
|
@ -905,12 +905,12 @@ class Trashbin {
|
|||
* get current size of trash bin from a given user
|
||||
*
|
||||
* @param string $user user who owns the trash bin
|
||||
* @return mixed trash bin size or false if no trash bin size is stored
|
||||
* @return integer trash bin size
|
||||
*/
|
||||
private static function getTrashbinSize($user) {
|
||||
$view = new \OC\Files\View('/' . $user);
|
||||
$fileInfo = $view->getFileInfo('/files_trashbin');
|
||||
return $fileInfo['size'];
|
||||
return isset($fileInfo['size']) ? $fileInfo['size'] : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1" ?>
|
||||
<database>
|
||||
|
||||
<name>*dbname*</name>
|
||||
<create>true</create>
|
||||
<overwrite>false</overwrite>
|
||||
|
||||
<charset>utf8</charset>
|
||||
|
||||
<table>
|
||||
|
||||
<name>*dbprefix*files_versions</name>
|
||||
|
||||
<declaration>
|
||||
|
||||
<field>
|
||||
<name>user</name>
|
||||
<type>text</type>
|
||||
<default></default>
|
||||
<notnull>true</notnull>
|
||||
<length>64</length>
|
||||
</field>
|
||||
<field>
|
||||
<name>size</name>
|
||||
<type>text</type>
|
||||
<default></default>
|
||||
<notnull>true</notnull>
|
||||
<length>50</length>
|
||||
</field>
|
||||
|
||||
</declaration>
|
||||
|
||||
</table>
|
||||
|
||||
</database>
|
|
@ -2,14 +2,6 @@
|
|||
|
||||
$installedVersion=OCP\Config::getAppValue('files_versions', 'installed_version');
|
||||
// move versions to new directory
|
||||
if (version_compare($installedVersion, '1.0.2', '<')) {
|
||||
$users = \OCP\User::getUsers();
|
||||
$datadir = \OCP\Config::getSystemValue('datadirectory').'/';
|
||||
foreach ($users as $user) {
|
||||
$oldPath = $datadir.$user.'/versions';
|
||||
$newPath = $datadir.$user.'/files_versions';
|
||||
if(is_dir($oldPath)) {
|
||||
rename($oldPath, $newPath);
|
||||
}
|
||||
}
|
||||
if (version_compare($installedVersion, '1.0.4', '<')) {
|
||||
\OC_DB::dropTable("files_versions");
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
1.0.3
|
||||
1.0.4
|
||||
|
|
|
@ -54,31 +54,12 @@ class Storage {
|
|||
* get current size of all versions from a given user
|
||||
*
|
||||
* @param string $user user who owns the versions
|
||||
* @return mixed versions size or false if no versions size is stored
|
||||
* @return int versions size
|
||||
*/
|
||||
private static function getVersionsSize($user) {
|
||||
$query = \OC_DB::prepare('SELECT `size` FROM `*PREFIX*files_versions` WHERE `user`=?');
|
||||
$result = $query->execute(array($user))->fetchAll();
|
||||
|
||||
if ($result) {
|
||||
return $result[0]['size'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* write to the database how much space is in use for versions
|
||||
*
|
||||
* @param string $user owner of the versions
|
||||
* @param int $size size of the versions
|
||||
*/
|
||||
private static function setVersionsSize($user, $size) {
|
||||
if ( self::getVersionsSize($user) === false) {
|
||||
$query = \OC_DB::prepare('INSERT INTO `*PREFIX*files_versions` (`size`, `user`) VALUES (?, ?)');
|
||||
}else {
|
||||
$query = \OC_DB::prepare('UPDATE `*PREFIX*files_versions` SET `size`=? WHERE `user`=?');
|
||||
}
|
||||
$query->execute(array($size, $user));
|
||||
$view = new \OC\Files\View('/' . $user);
|
||||
$fileInfo = $view->getFileInfo('/files_versions');
|
||||
return isset($fileInfo['size']) ? $fileInfo['size'] : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -115,16 +96,13 @@ class Storage {
|
|||
self::createMissingDirectories($filename, $users_view);
|
||||
|
||||
$versionsSize = self::getVersionsSize($uid);
|
||||
if ( $versionsSize === false || $versionsSize < 0 ) {
|
||||
$versionsSize = self::calculateSize($uid);
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
$versionsSize = self::expire($filename, $versionsSize, $neededSpace);
|
||||
self::expire($filename, $versionsSize, $neededSpace);
|
||||
|
||||
// disable proxy to prevent multiple fopen calls
|
||||
$proxyStatus = \OC_FileProxy::$enabled;
|
||||
|
@ -138,10 +116,6 @@ class Storage {
|
|||
|
||||
// reset proxy state
|
||||
\OC_FileProxy::$enabled = $proxyStatus;
|
||||
|
||||
$versionsSize += $users_view->filesize('files'.$filename);
|
||||
|
||||
self::setVersionsSize($uid, $versionsSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,17 +147,11 @@ class Storage {
|
|||
$abs_path = $versions_fileview->getLocalFile($filename . '.v');
|
||||
$versions = self::getVersions($uid, $filename);
|
||||
if (!empty($versions)) {
|
||||
$versionsSize = self::getVersionsSize($uid);
|
||||
if ($versionsSize === false || $versionsSize < 0) {
|
||||
$versionsSize = self::calculateSize($uid);
|
||||
}
|
||||
foreach ($versions as $v) {
|
||||
\OC_Hook::emit('\OCP\Versions', 'preDelete', array('path' => $abs_path . $v['version']));
|
||||
unlink($abs_path . $v['version']);
|
||||
\OC_Hook::emit('\OCP\Versions', 'delete', array('path' => $abs_path . $v['version']));
|
||||
$versionsSize -= $v['size'];
|
||||
}
|
||||
self::setVersionsSize($uid, $versionsSize);
|
||||
}
|
||||
}
|
||||
unset(self::$deletedFiles[$path]);
|
||||
|
@ -344,33 +312,6 @@ class Storage {
|
|||
return $query->execute(array($uid));
|
||||
}
|
||||
|
||||
/**
|
||||
* get the size of all stored versions from a given user
|
||||
* @param string $uid id from the user
|
||||
* @return int size of versions
|
||||
*/
|
||||
private static function calculateSize($uid) {
|
||||
if (\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED) == 'true') {
|
||||
$view = new \OC\Files\View('/' . $uid . '/files_versions');
|
||||
|
||||
$size = 0;
|
||||
|
||||
$dirContent = $view->getDirectoryContent('/');
|
||||
|
||||
while (!empty($dirContent)) {
|
||||
$path = reset($dirContent);
|
||||
if ($path['type'] === 'dir') {
|
||||
$dirContent = array_merge($dirContent, $view->getDirectoryContent(substr($path['path'], strlen('files_versions'))));
|
||||
} else {
|
||||
$size += $view->filesize(substr($path['path'], strlen('files_versions')));
|
||||
}
|
||||
unset($dirContent[key($dirContent)]);
|
||||
}
|
||||
|
||||
return $size;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns all stored file versions from a given user
|
||||
* @param string $uid id of the user
|
||||
|
@ -500,9 +441,6 @@ class Storage {
|
|||
// make sure that we have the current size of the version history
|
||||
if ( $versionsSize === null ) {
|
||||
$versionsSize = self::getVersionsSize($uid);
|
||||
if ( $versionsSize === false || $versionsSize < 0 ) {
|
||||
$versionsSize = self::calculateSize($uid);
|
||||
}
|
||||
}
|
||||
|
||||
// calculate available space for version history
|
||||
|
|
2
lib/private/files/cache/homecache.php
vendored
2
lib/private/files/cache/homecache.php
vendored
|
@ -17,7 +17,7 @@ class HomeCache extends Cache {
|
|||
* @return int
|
||||
*/
|
||||
public function calculateFolderSize($path, $entry = null) {
|
||||
if ($path !== '/' and $path !== '' and $path !== 'files' and $path !== 'files_trashbin') {
|
||||
if ($path !== '/' and $path !== '' and $path !== 'files' and $path !== 'files_trashbin' and $path !== 'files_versions') {
|
||||
return parent::calculateFolderSize($path, $entry);
|
||||
} elseif ($path === '' or $path === '/') {
|
||||
// since the size of / isn't used (the size of /files is used instead) there is no use in calculating it
|
||||
|
|
Loading…
Reference in a new issue