From 7552390031ee10ed5006ef927fa1f55cdd148554 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 30 Mar 2012 18:12:33 +0200 Subject: [PATCH] add path_hash to the filesystem cache --- db_structure.xml | 28 ++++++++++++++++++++++------ lib/filecache.php | 28 ++++++++++++++-------------- lib/util.php | 2 +- 3 files changed, 37 insertions(+), 21 deletions(-) diff --git a/db_structure.xml b/db_structure.xml index 5eef44d8e8..82d2a731d4 100644 --- a/db_structure.xml +++ b/db_structure.xml @@ -64,6 +64,15 @@ 512 + + path_hash + text + + + true + 32 + + parent integer @@ -79,7 +88,7 @@ true - 512 + 300 @@ -159,14 +168,13 @@ 1 - + parent_index @@ -176,6 +184,14 @@ + + name_index + + name + ascending + + + parent_name_index diff --git a/lib/filecache.php b/lib/filecache.php index 280a9929db..a8c48e3f14 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -59,8 +59,8 @@ class OC_FileCache{ $root=''; } $path=$root.$path; - $query=OC_DB::prepare('SELECT ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE path=?'); - $result=$query->execute(array($path))->fetchRow(); + $query=OC_DB::prepare('SELECT ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE path_hash=?'); + $result=$query->execute(array(md5($path)))->fetchRow(); if(is_array($result)){ return $result; }else{ @@ -111,8 +111,8 @@ class OC_FileCache{ } $mimePart=dirname($data['mimetype']); $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(?,?,?,?,?,?,?,?,?,?,?,?)'); - $result=$query->execute(array($parent,basename($path),$path,$data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart,$user,$data['writable'],$data['encrypted'],$data['versioned'])); + $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,md5($path),$data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart,$user,$data['writable'],$data['encrypted'],$data['versioned'])); if(OC_DB::isError($result)){ OC_Log::write('files','error while writing file('.$path.') to cache',OC_Log::ERROR); } @@ -162,8 +162,8 @@ class OC_FileCache{ $oldPath=$root.$oldPath; $newPath=$root.$newPath; $newParent=self::getParentId($newPath); - $query=OC_DB::prepare('UPDATE *PREFIX*fscache SET parent=? ,name=?, path=? WHERE path=?'); - $query->execute(array($newParent,basename($newPath),$newPath,$oldPath)); + $query=OC_DB::prepare('UPDATE *PREFIX*fscache SET parent=? ,name=?, path=?, path_hash=? WHERE path_hash=?'); + $query->execute(array($newParent,basename($newPath),$newPath,md5($newPath),md5($oldPath))); } /** @@ -285,12 +285,12 @@ class OC_FileCache{ * @return int */ 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)){ OC_Log::write('files','error while getting file id of '.$path,OC_Log::ERROR); return -1; } - $result=$query->execute(array($path)); + $result=$query->execute(array(md5($path))); if(OC_DB::isError($result)){ OC_Log::write('files','error while getting file id of '.$path,OC_Log::ERROR); return -1; @@ -367,8 +367,8 @@ class OC_FileCache{ } } $path=$root.$path; - $query=OC_DB::prepare('SELECT ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE path=?'); - $result=$query->execute(array($path))->fetchRow(); + $query=OC_DB::prepare('SELECT ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE path_hash=?'); + $result=$query->execute(array(md5($path)))->fetchRow(); if(is_array($result)){ if(isset(self::$savedData[$path])){ $result=array_merge($result,self::$savedData[$path]); @@ -389,8 +389,8 @@ class OC_FileCache{ } } $path=$root.$path; - $query=OC_DB::prepare('SELECT size FROM *PREFIX*fscache WHERE path=?'); - $result=$query->execute(array($path)); + $query=OC_DB::prepare('SELECT size FROM *PREFIX*fscache WHERE path_hash=?'); + $result=$query->execute(array(md5($path))); if($row=$result->fetchRow()){ return $row['size']; }else{//file not in cache @@ -579,8 +579,8 @@ class OC_FileCache{ $mtime=$view->filemtime($path); $isDir=$view->is_dir($path); $path=$root.$path; - $query=OC_DB::prepare('SELECT mtime FROM *PREFIX*fscache WHERE path=?'); - $result=$query->execute(array($path)); + $query=OC_DB::prepare('SELECT mtime FROM *PREFIX*fscache WHERE path_hash=?'); + $result=$query->execute(array(md5($path))); if($row=$result->fetchRow()){ $cachedMTime=$row['mtime']; return ($mtime>$cachedMTime); diff --git a/lib/util.php b/lib/util.php index fa5b3daaab..529b6d958f 100644 --- a/lib/util.php +++ b/lib/util.php @@ -66,7 +66,7 @@ class OC_Util { * @return array */ public static function getVersion(){ - return array(3,00,3); + return array(3,00,4); } /**