diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2014-05-06 13:55:26 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2014-06-02 18:55:13 +0200 |
commit | 7ad0fee0b56d9ab678cbb52128d427ebd641b05e (patch) | |
tree | b8b99b661cbeb7772f927d070eb6e18cd5408a92 /apps/files_versions | |
parent | 390d8e53b4349af2265085f25c2784c620fbf4ae (diff) | |
download | nextcloud-server-7ad0fee0b56d9ab678cbb52128d427ebd641b05e.tar.gz nextcloud-server-7ad0fee0b56d9ab678cbb52128d427ebd641b05e.zip |
let file cache handle the versions size
Diffstat (limited to 'apps/files_versions')
-rw-r--r-- | apps/files_versions/appinfo/database.xml | 35 | ||||
-rw-r--r-- | apps/files_versions/appinfo/update.php | 13 | ||||
-rw-r--r-- | apps/files_versions/appinfo/version | 2 | ||||
-rw-r--r-- | apps/files_versions/lib/versions.php | 49 |
4 files changed, 13 insertions, 86 deletions
diff --git a/apps/files_versions/appinfo/database.xml b/apps/files_versions/appinfo/database.xml deleted file mode 100644 index d3854776980..00000000000 --- a/apps/files_versions/appinfo/database.xml +++ /dev/null @@ -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> diff --git a/apps/files_versions/appinfo/update.php b/apps/files_versions/appinfo/update.php index 52a4850758a..ee6d3c14c9a 100644 --- a/apps/files_versions/appinfo/update.php +++ b/apps/files_versions/appinfo/update.php @@ -2,14 +2,7 @@ $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', '<')) { + $query = \OCP\DB::prepare("DROP TABLE `*PREFIX*files_versions`"); + $query->execute(array()); } diff --git a/apps/files_versions/appinfo/version b/apps/files_versions/appinfo/version index e4c0d46e55f..ee90284c27f 100644 --- a/apps/files_versions/appinfo/version +++ b/apps/files_versions/appinfo/version @@ -1 +1 @@ -1.0.3
\ No newline at end of file +1.0.4 diff --git a/apps/files_versions/lib/versions.php b/apps/files_versions/lib/versions.php index 56e1dfc2e24..8dc01d18ad9 100644 --- a/apps/files_versions/lib/versions.php +++ b/apps/files_versions/lib/versions.php @@ -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]); @@ -345,6 +313,7 @@ class Storage { } /** +<<<<<<< HEAD * get the size of all stored versions from a given user * @param string $uid id from the user * @return int size of versions @@ -373,6 +342,9 @@ class Storage { /** * returns all stored file versions from a given user +======= + * @brief returns all stored file versions from a given user +>>>>>>> 2f97e2f... let file cache handle the versions size * @param string $uid id of the user * @return array with contains two arrays 'all' which contains all versions sorted by age and 'by_file' which contains all versions sorted by filename */ @@ -500,9 +472,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 |