add path_hash to the filesystem cache

This commit is contained in:
Robin Appelman 2012-03-30 18:12:33 +02:00
parent 523fdda399
commit 7552390031
3 changed files with 37 additions and 21 deletions

View File

@ -64,6 +64,15 @@
<length>512</length> <length>512</length>
</field> </field>
<field>
<name>path_hash</name>
<type>text</type>
<default>
</default>
<notnull>true</notnull>
<length>32</length>
</field>
<field> <field>
<name>parent</name> <name>parent</name>
<type>integer</type> <type>integer</type>
@ -79,7 +88,7 @@
<default> <default>
</default> </default>
<notnull>true</notnull> <notnull>true</notnull>
<length>512</length> <length>300</length>
</field> </field>
<field> <field>
@ -159,14 +168,13 @@
<length>1</length> <length>1</length>
</field> </field>
<!--<index> <index>
<name>fscache_path_index</name> <name>fscache_path_hash_index</name>
<unique>true</unique>
<field> <field>
<name>path</name> <name>path_hash</name>
<sorting>ascending</sorting> <sorting>ascending</sorting>
</field> </field>
</index>--> </index>
<index> <index>
<name>parent_index</name> <name>parent_index</name>
@ -176,6 +184,14 @@
</field> </field>
</index> </index>
<index>
<name>name_index</name>
<field>
<name>name</name>
<sorting>ascending</sorting>
</field>
</index>
<index> <index>
<name>parent_name_index</name> <name>parent_name_index</name>
<field> <field>

View File

@ -59,8 +59,8 @@ class OC_FileCache{
$root=''; $root='';
} }
$path=$root.$path; $path=$root.$path;
$query=OC_DB::prepare('SELECT ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE path=?'); $query=OC_DB::prepare('SELECT ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE path_hash=?');
$result=$query->execute(array($path))->fetchRow(); $result=$query->execute(array(md5($path)))->fetchRow();
if(is_array($result)){ if(is_array($result)){
return $result; return $result;
}else{ }else{
@ -111,8 +111,8 @@ class OC_FileCache{
} }
$mimePart=dirname($data['mimetype']); $mimePart=dirname($data['mimetype']);
$user=OC_User::getUser(); $user=OC_User::getUser();
$query=OC_DB::prepare('INSERT INTO *PREFIX*fscache(parent, name, path, size, mtime, ctime, mimetype, mimepart,user,writable,encrypted,versioned) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)'); $query=OC_DB::prepare('INSERT INTO *PREFIX*fscache(parent, name, path, path_hash, size, mtime, ctime, mimetype, mimepart,user,writable,encrypted,versioned) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)');
$result=$query->execute(array($parent,basename($path),$path,$data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart,$user,$data['writable'],$data['encrypted'],$data['versioned'])); $result=$query->execute(array($parent,basename($path),$path,md5($path),$data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart,$user,$data['writable'],$data['encrypted'],$data['versioned']));
if(OC_DB::isError($result)){ if(OC_DB::isError($result)){
OC_Log::write('files','error while writing file('.$path.') to cache',OC_Log::ERROR); OC_Log::write('files','error while writing file('.$path.') to cache',OC_Log::ERROR);
} }
@ -162,8 +162,8 @@ class OC_FileCache{
$oldPath=$root.$oldPath; $oldPath=$root.$oldPath;
$newPath=$root.$newPath; $newPath=$root.$newPath;
$newParent=self::getParentId($newPath); $newParent=self::getParentId($newPath);
$query=OC_DB::prepare('UPDATE *PREFIX*fscache SET parent=? ,name=?, path=? WHERE path=?'); $query=OC_DB::prepare('UPDATE *PREFIX*fscache SET parent=? ,name=?, path=?, path_hash=? WHERE path_hash=?');
$query->execute(array($newParent,basename($newPath),$newPath,$oldPath)); $query->execute(array($newParent,basename($newPath),$newPath,md5($newPath),md5($oldPath)));
} }
/** /**
@ -285,12 +285,12 @@ class OC_FileCache{
* @return int * @return int
*/ */
private static function getFileId($path){ private static function getFileId($path){
$query=OC_DB::prepare('SELECT id FROM *PREFIX*fscache WHERE path=?'); $query=OC_DB::prepare('SELECT id FROM *PREFIX*fscache WHERE path_hash=?');
if(OC_DB::isError($query)){ if(OC_DB::isError($query)){
OC_Log::write('files','error while getting file id of '.$path,OC_Log::ERROR); OC_Log::write('files','error while getting file id of '.$path,OC_Log::ERROR);
return -1; return -1;
} }
$result=$query->execute(array($path)); $result=$query->execute(array(md5($path)));
if(OC_DB::isError($result)){ if(OC_DB::isError($result)){
OC_Log::write('files','error while getting file id of '.$path,OC_Log::ERROR); OC_Log::write('files','error while getting file id of '.$path,OC_Log::ERROR);
return -1; return -1;
@ -367,8 +367,8 @@ class OC_FileCache{
} }
} }
$path=$root.$path; $path=$root.$path;
$query=OC_DB::prepare('SELECT ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE path=?'); $query=OC_DB::prepare('SELECT ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE path_hash=?');
$result=$query->execute(array($path))->fetchRow(); $result=$query->execute(array(md5($path)))->fetchRow();
if(is_array($result)){ if(is_array($result)){
if(isset(self::$savedData[$path])){ if(isset(self::$savedData[$path])){
$result=array_merge($result,self::$savedData[$path]); $result=array_merge($result,self::$savedData[$path]);
@ -389,8 +389,8 @@ class OC_FileCache{
} }
} }
$path=$root.$path; $path=$root.$path;
$query=OC_DB::prepare('SELECT size FROM *PREFIX*fscache WHERE path=?'); $query=OC_DB::prepare('SELECT size FROM *PREFIX*fscache WHERE path_hash=?');
$result=$query->execute(array($path)); $result=$query->execute(array(md5($path)));
if($row=$result->fetchRow()){ if($row=$result->fetchRow()){
return $row['size']; return $row['size'];
}else{//file not in cache }else{//file not in cache
@ -579,8 +579,8 @@ class OC_FileCache{
$mtime=$view->filemtime($path); $mtime=$view->filemtime($path);
$isDir=$view->is_dir($path); $isDir=$view->is_dir($path);
$path=$root.$path; $path=$root.$path;
$query=OC_DB::prepare('SELECT mtime FROM *PREFIX*fscache WHERE path=?'); $query=OC_DB::prepare('SELECT mtime FROM *PREFIX*fscache WHERE path_hash=?');
$result=$query->execute(array($path)); $result=$query->execute(array(md5($path)));
if($row=$result->fetchRow()){ if($row=$result->fetchRow()){
$cachedMTime=$row['mtime']; $cachedMTime=$row['mtime'];
return ($mtime>$cachedMTime); return ($mtime>$cachedMTime);

View File

@ -66,7 +66,7 @@ class OC_Util {
* @return array * @return array
*/ */
public static function getVersion(){ public static function getVersion(){
return array(3,00,3); return array(3,00,4);
} }
/** /**