use numeric ids for storages in the filecache
This commit is contained in:
parent
8951769cae
commit
b12abb2c94
4 changed files with 92 additions and 15 deletions
|
@ -58,6 +58,42 @@
|
|||
|
||||
</table>
|
||||
|
||||
<table>
|
||||
|
||||
<name>*dbprefix*storages</name>
|
||||
|
||||
<declaration>
|
||||
|
||||
<field>
|
||||
<name>id</name>
|
||||
<type>text</type>
|
||||
<default></default>
|
||||
<notnull>true</notnull>
|
||||
<length>64</length>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>numeric_id</name>
|
||||
<type>integer</type>
|
||||
<default>0</default>
|
||||
<notnull>true</notnull>
|
||||
<autoincrement>1</autoincrement>
|
||||
<length>4</length>
|
||||
</field>
|
||||
|
||||
<index>
|
||||
<name>storages_id_index</name>
|
||||
<unique>true</unique>
|
||||
<field>
|
||||
<name>id</name>
|
||||
<sorting>ascending</sorting>
|
||||
</field>
|
||||
</index>
|
||||
|
||||
</declaration>
|
||||
|
||||
</table>
|
||||
|
||||
<table>
|
||||
|
||||
<name>*dbprefix*filecache</name>
|
||||
|
@ -75,10 +111,10 @@
|
|||
|
||||
<field>
|
||||
<name>storage</name>
|
||||
<type>text</type>
|
||||
<type>integer</type>
|
||||
<default></default>
|
||||
<notnull>true</notnull>
|
||||
<length>64</length>
|
||||
<length>4</length>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
|
|
44
lib/files/cache/cache.php
vendored
44
lib/files/cache/cache.php
vendored
|
@ -29,6 +29,13 @@ class Cache {
|
|||
*/
|
||||
private $storageId;
|
||||
|
||||
/**
|
||||
* numeric storage id
|
||||
*
|
||||
* @var int $numericId
|
||||
*/
|
||||
private $numericId;
|
||||
|
||||
/**
|
||||
* @param \OC\Files\Storage\Storage|string $storage
|
||||
*/
|
||||
|
@ -38,6 +45,20 @@ class Cache {
|
|||
} else {
|
||||
$this->storageId = $storage;
|
||||
}
|
||||
|
||||
$query = \OC_DB::prepare('SELECT `numeric_id` FROM `*PREFIX*storages` WHERE `id` = ?');
|
||||
$result = $query->execute(array($this->storageId));
|
||||
if ($row = $result->fetchRow()) {
|
||||
$this->numericId = $row['numeric_id'];
|
||||
} else {
|
||||
$query = \OC_DB::prepare('INSERT INTO `*PREFIX*storages`(`id`) VALUES(?)');
|
||||
$query->execute(array($this->storageId));
|
||||
$this->numericId = \OC_DB::insertid('*PREFIX*filecache');
|
||||
}
|
||||
}
|
||||
|
||||
public function getNumericStorageId() {
|
||||
return $this->numericId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,7 +70,7 @@ class Cache {
|
|||
public function get($file) {
|
||||
if (is_string($file) or $file == '') {
|
||||
$where = 'WHERE `storage` = ? AND `path_hash` = ?';
|
||||
$params = array($this->storageId, md5($file));
|
||||
$params = array($this->numericId, md5($file));
|
||||
} else { //file id
|
||||
$where = 'WHERE `fileid` = ?';
|
||||
$params = array($file);
|
||||
|
@ -128,7 +149,7 @@ class Cache {
|
|||
|
||||
list($queryParts, $params) = $this->buildParts($data);
|
||||
$queryParts[] = '`storage`';
|
||||
$params[] = $this->storageId;
|
||||
$params[] = $this->numericId;
|
||||
$valuesPlaceholder = array_fill(0, count($queryParts), '?');
|
||||
|
||||
$query = \OC_DB::prepare('INSERT INTO `*PREFIX*filecache`(' . implode(', ', $queryParts) . ') VALUES(' . implode(', ', $valuesPlaceholder) . ')');
|
||||
|
@ -189,7 +210,7 @@ class Cache {
|
|||
$pathHash = md5($file);
|
||||
|
||||
$query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?');
|
||||
$result = $query->execute(array($this->storageId, $pathHash));
|
||||
$result = $query->execute(array($this->numericId, $pathHash));
|
||||
|
||||
if ($row = $result->fetchRow()) {
|
||||
return $row['fileid'];
|
||||
|
@ -273,7 +294,10 @@ class Cache {
|
|||
* remove all entries for files that are stored on the storage from the cache
|
||||
*/
|
||||
public function clear() {
|
||||
$query = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache` WHERE storage=?');
|
||||
$query = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache` WHERE storage = ?');
|
||||
$query->execute(array($this->numericId));
|
||||
|
||||
$query = \OC_DB::prepare('DELETE FROM `*PREFIX*storages` WHERE id = ?');
|
||||
$query->execute(array($this->storageId));
|
||||
}
|
||||
|
||||
|
@ -285,7 +309,7 @@ class Cache {
|
|||
public function getStatus($file) {
|
||||
$pathHash = md5($file);
|
||||
$query = \OC_DB::prepare('SELECT `size` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?');
|
||||
$result = $query->execute(array($this->storageId, $pathHash));
|
||||
$result = $query->execute(array($this->numericId, $pathHash));
|
||||
if ($row = $result->fetchRow()) {
|
||||
if ((int)$row['size'] === -1) {
|
||||
return self::SHALLOW;
|
||||
|
@ -312,7 +336,7 @@ class Cache {
|
|||
SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`
|
||||
FROM `*PREFIX*filecache` WHERE `name` LIKE ? AND `storage` = ?'
|
||||
);
|
||||
$result = $query->execute(array($pattern, $this->storageId));
|
||||
$result = $query->execute(array($pattern, $this->numericId));
|
||||
$files = array();
|
||||
while ($row = $result->fetchRow()) {
|
||||
$files[] = $row;
|
||||
|
@ -336,7 +360,7 @@ class Cache {
|
|||
SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`
|
||||
FROM `*PREFIX*filecache` WHERE ' . $where . ' AND `storage` = ?'
|
||||
);
|
||||
$result = $query->execute(array($mimetype, $this->storageId));
|
||||
$result = $query->execute(array($mimetype, $this->numericId));
|
||||
return $result->fetchAll();
|
||||
}
|
||||
|
||||
|
@ -368,7 +392,7 @@ class Cache {
|
|||
return 0;
|
||||
}
|
||||
$query = \OC_DB::prepare('SELECT `size` FROM `*PREFIX*filecache` WHERE `parent` = ? AND `storage` = ?');
|
||||
$result = $query->execute(array($id, $this->storageId));
|
||||
$result = $query->execute(array($id, $this->numericId));
|
||||
$totalSize = 0;
|
||||
$hasChilds = 0;
|
||||
while ($row = $result->fetchRow()) {
|
||||
|
@ -395,7 +419,7 @@ class Cache {
|
|||
*/
|
||||
public function getAll() {
|
||||
$query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ?');
|
||||
$result = $query->execute(array($this->storageId));
|
||||
$result = $query->execute(array($this->numericId));
|
||||
$ids = array();
|
||||
while ($row = $result->fetchRow()) {
|
||||
$ids[] = $row['fileid'];
|
||||
|
@ -414,7 +438,7 @@ class Cache {
|
|||
*/
|
||||
public function getIncomplete() {
|
||||
$query = \OC_DB::prepare('SELECT `path` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `size` = -1 ORDER BY `fileid` DESC LIMIT 1');
|
||||
$query->execute(array($this->storageId));
|
||||
$query->execute(array($this->numericId));
|
||||
if ($row = $query->fetchRow()) {
|
||||
return $row['path'];
|
||||
} else {
|
||||
|
|
21
lib/files/cache/upgrade.php
vendored
21
lib/files/cache/upgrade.php
vendored
|
@ -11,6 +11,8 @@ namespace OC\Files\Cache;
|
|||
class Upgrade {
|
||||
static $permissionsCaches = array();
|
||||
|
||||
static $numericIds = array();
|
||||
|
||||
static function upgrade() {
|
||||
$insertQuery = \OC_DB::prepare('INSERT INTO `*PREFIX*filecache`( `fileid`, `storage`, `path`, `path_hash`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted` )
|
||||
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
|
||||
|
@ -32,7 +34,7 @@ class Upgrade {
|
|||
$checkExistingQuery = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `fileid` = ?');
|
||||
|
||||
while ($row = $oldEntriesResult->fetchRow()) {
|
||||
if($checkExistingQuery->execute(array($row['id']))->fetchRow()){
|
||||
if ($checkExistingQuery->execute(array($row['id']))->fetchRow()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -42,7 +44,7 @@ class Upgrade {
|
|||
* @var string $internalPath;
|
||||
*/
|
||||
$pathHash = md5($internalPath);
|
||||
$storageId = $storage->getId();
|
||||
$storageId = self::getNumericId($storage);
|
||||
$parentId = ($internalPath === '') ? -1 : $row['parent'];
|
||||
|
||||
$insertQuery->execute(array($row['id'], $storageId, $internalPath, $pathHash, $parentId, $row['name'], $row['mimetype'], $row['mimepart'], $row['size'], $row['mtime'], $row['encrypted']));
|
||||
|
@ -64,4 +66,19 @@ class Upgrade {
|
|||
}
|
||||
return self::$permissionsCaches[$storageId];
|
||||
}
|
||||
|
||||
/**
|
||||
* get the numeric storage id
|
||||
*
|
||||
* @param \OC\Files\Storage\Storage $storage
|
||||
* @return int
|
||||
*/
|
||||
static function getNumericId($storage) {
|
||||
$storageId = $storage->getId();
|
||||
if (!isset(self::$numericIds[$storageId])) {
|
||||
$cache = new Cache($storage);
|
||||
self::$numericIds[$storageId] = $cache->getNumericStorageId();
|
||||
}
|
||||
return self::$numericIds[$storageId];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ class OC_Util {
|
|||
*/
|
||||
public static function getVersion() {
|
||||
// hint: We only can count up. So the internal version number of ownCloud 4.5 will be 4.90.0. This is not visible to the user
|
||||
return array(4,91,02);
|
||||
return array(4,91,04);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue