fix several problems in the new filecache in order to complete the tests
This commit is contained in:
parent
73eedd8fc8
commit
97b0eabc85
|
@ -23,22 +23,25 @@ class Cache {
|
||||||
static public function get($file) {
|
static public function get($file) {
|
||||||
if ($file instanceof \OC\Files\File) {
|
if ($file instanceof \OC\Files\File) {
|
||||||
$where = 'WHERE `storage` = ? AND `path_hash` = ?';
|
$where = 'WHERE `storage` = ? AND `path_hash` = ?';
|
||||||
$params = array($file->getStorageId(), $file->getInternalPath());
|
$params = array($file->getStorageId(), md5($file->getInternalPath()));
|
||||||
} else { //file id
|
} else { //file id
|
||||||
$where = 'WHERE `fileid` = ?';
|
$where = 'WHERE `fileid` = ?';
|
||||||
$params = array($file);
|
$params = array($file);
|
||||||
}
|
}
|
||||||
$query = \OC_DB::prepare(
|
$query = \OC_DB::prepare(
|
||||||
'SELECT `id`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`
|
'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`
|
||||||
FROM `*PREFIX*filecache` ' . $where);
|
FROM `*PREFIX*filecache` ' . $where);
|
||||||
$result = $query->execute($params);
|
$result = $query->execute($params);
|
||||||
|
$data = $result->fetchRow();
|
||||||
|
|
||||||
//merge partial data
|
//merge partial data
|
||||||
$key = $file->getStorageId() . '::' . $file->getInternalPath();
|
if (!$data and $file instanceof \OC\Files\File) {
|
||||||
if (isset(self::$partial[$key])) {
|
$key = $file->getStorageId() . '::' . $file->getInternalPath();
|
||||||
$result=array_merge($result, self::$partial[$key]);
|
if (isset(self::$partial[$key])) {
|
||||||
|
$data = self::$partial[$key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $result->fetchRow();
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,13 +53,13 @@ class Cache {
|
||||||
* @return int file id
|
* @return int file id
|
||||||
*/
|
*/
|
||||||
static public function put(\OC\Files\File $file, array $data) {
|
static public function put(\OC\Files\File $file, array $data) {
|
||||||
if ($id = self::getId($file) > -1) {
|
if (($id = self::getId($file)) > -1) {
|
||||||
self::update($id, $data);
|
self::update($id, $data);
|
||||||
return $id;
|
return $id;
|
||||||
} else {
|
} else {
|
||||||
$key = $file->getStorageId() . '::' . $file->getInternalPath();
|
$key = $file->getStorageId() . '::' . $file->getInternalPath();
|
||||||
if (isset(self::$partial[$key])) { //add any saved partial data
|
if (isset(self::$partial[$key])) { //add any saved partial data
|
||||||
$data = array_merge($data, self::$partial[$key]);
|
$data = array_merge(self::$partial[$key], $data);
|
||||||
unset(self::$partial[$key]);
|
unset(self::$partial[$key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +80,7 @@ class Cache {
|
||||||
$params[] = $file->getStorageId();
|
$params[] = $file->getStorageId();
|
||||||
$valuesPlaceholder = array_fill(0, count($queryParts), '?');
|
$valuesPlaceholder = array_fill(0, count($queryParts), '?');
|
||||||
|
|
||||||
$query = \OC_DB::prepare('INSERT INTO `*PREFIX*filecache`(' . implode(', ', $queryParts) . ' VALUES(' . implode(', ', $valuesPlaceholder) . ')');
|
$query = \OC_DB::prepare('INSERT INTO `*PREFIX*filecache`(' . implode(', ', $queryParts) . ') VALUES(' . implode(', ', $valuesPlaceholder) . ')');
|
||||||
$query->execute($params);
|
$query->execute($params);
|
||||||
|
|
||||||
return \OC_DB::insertid('*PREFIX*filecache');
|
return \OC_DB::insertid('*PREFIX*filecache');
|
||||||
|
@ -135,11 +138,11 @@ class Cache {
|
||||||
$storageId = $file->getStorageId();
|
$storageId = $file->getStorageId();
|
||||||
$pathHash = md5($file->getInternalPath());
|
$pathHash = md5($file->getInternalPath());
|
||||||
|
|
||||||
$query = \OC_DB::prepare('SELECT id FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?');
|
$query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?');
|
||||||
$result = $query->execute(array($storageId, $pathHash));
|
$result = $query->execute(array($storageId, $pathHash));
|
||||||
|
|
||||||
if ($row = $result->fetchRow()) {
|
if ($row = $result->fetchRow()) {
|
||||||
return $row['id'];
|
return $row['fileid'];
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -175,7 +178,7 @@ class Cache {
|
||||||
*
|
*
|
||||||
* @param \OC\Files\File $file
|
* @param \OC\Files\File $file
|
||||||
*/
|
*/
|
||||||
public function remove(\OC\Files\File $file) {
|
static public function remove(\OC\Files\File $file) {
|
||||||
$storageId = $file->getStorageId();
|
$storageId = $file->getStorageId();
|
||||||
$pathHash = md5($file->getInternalPath());
|
$pathHash = md5($file->getInternalPath());
|
||||||
$query = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?');
|
$query = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?');
|
||||||
|
@ -187,7 +190,7 @@ class Cache {
|
||||||
*
|
*
|
||||||
* @param \OC\Files\Storage\Storage $storage
|
* @param \OC\Files\Storage\Storage $storage
|
||||||
*/
|
*/
|
||||||
public function removeStorage(\OC\Files\Storage\Storage $storage) {
|
static public function removeStorage(\OC\Files\Storage\Storage $storage) {
|
||||||
$storageId = $storage->getId();
|
$storageId = $storage->getId();
|
||||||
$query = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache` WHERE storage=?');
|
$query = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache` WHERE storage=?');
|
||||||
$query->execute(array($storageId));
|
$query->execute(array($storageId));
|
||||||
|
|
Loading…
Reference in New Issue