diff options
author | Robin Appelman <icewind@owncloud.com> | 2012-01-31 16:12:49 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2012-01-31 16:12:49 +0100 |
commit | c46f701771db9285e70a5b1d5a4b641046bf703c (patch) | |
tree | 2c020015d04ede4be9f158d48a36c1eb158c0e72 | |
parent | df67c35017d8794a4b1c83fd4e41658b2e6d0e75 (diff) | |
download | nextcloud-server-c46f701771db9285e70a5b1d5a4b641046bf703c.tar.gz nextcloud-server-c46f701771db9285e70a5b1d5a4b641046bf703c.zip |
use filesystem cache for searching
-rw-r--r-- | lib/filecache.php | 25 | ||||
-rw-r--r-- | lib/filesystem.php | 2 | ||||
-rw-r--r-- | lib/filesystemview.php | 17 | ||||
-rw-r--r-- | lib/search/provider/file.php | 11 |
4 files changed, 26 insertions, 29 deletions
diff --git a/lib/filecache.php b/lib/filecache.php index 6dbaef4bbfa..689680624a4 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -79,8 +79,9 @@ class OC_FileCache{ $data['versioned']=false; } $mimePart=dirname($data['mimetype']); - $query=OC_DB::prepare('INSERT INTO *PREFIX*fscache(parent, name, path, size, mtime, ctime, mimetype, mimepart) VALUES(?,?,?,?,?,?,?,?)'); - $query->execute(array($parent,basename($path),$path,$data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart)); + $user=OC_User::getUser(); + $query=OC_DB::prepare('INSERT INTO *PREFIX*fscache(parent, name, path, size, mtime, ctime, mimetype, mimepart,user) VALUES(?,?,?,?,?,?,?,?,?)'); + $query->execute(array($parent,basename($path),$path,$data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart,$user)); } @@ -133,14 +134,26 @@ class OC_FileCache{ /** * return array of filenames matching the querty * @param string $query + * @param boolean $returnData * @return array of filepaths */ - public static function search($search){ - $query=OC_DB::prepare('SELECT path FROM *PREFIX*fscache WHERE name LIKE ?'); - $result=$query->execute(array("%$search%")); + public static function search($search,$returnData=false){ + $root=OC_Filesystem::getRoot(); + $rootLen=strlen($root); + if(!$returnData){ + $query=OC_DB::prepare('SELECT path FROM *PREFIX*fscache WHERE name LIKE ? AND user=?'); + }else{ + $query=OC_DB::prepare('SELECT * FROM *PREFIX*fscache WHERE name LIKE ? AND user=?'); + } + $result=$query->execute(array("%$search%",OC_User::getUser())); $names=array(); while($row=$result->fetchRow()){ - $names[]=$row['path']; + if(!$returnData){ + $names[]=substr($row['path'],$rootLen); + }else{ + $row['path']=substr($row['path'],$rootLen); + $names[]=$row; + } } return $names; } diff --git a/lib/filesystem.php b/lib/filesystem.php index 8502cfc08bb..5062ecf5c18 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -374,7 +374,7 @@ class OC_Filesystem{ } static public function search($query){ - return self::$defaultInstance->search($query); + return OC_FileCache::search($query); } } diff --git a/lib/filesystemview.php b/lib/filesystemview.php index 9687a8bceb4..6c2ca916310 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -279,23 +279,6 @@ class OC_FilesystemView { return $this->basicOperation('free_space',$path); } - public function search($query){ - $files=array(); - $fakeRoot=$this->$fakeRoot; - $fakeRootLength=strlen($fakeRoot); - $results=OC_FileCache::search($query); - if(is_array($results)){ - foreach($results as $result){ - $file=str_replace('//','/',$mountpoint.$result); - if(substr($file,0,$fakeRootLength)==$fakeRoot){ - $file=substr($file,$fakeRootLength); - $files[]=$file; - } - } - } - return $files; - } - /** * abstraction for running most basic operations * @param string $operation diff --git a/lib/search/provider/file.php b/lib/search/provider/file.php index 5fd35fa3e52..c3dc2942aef 100644 --- a/lib/search/provider/file.php +++ b/lib/search/provider/file.php @@ -2,14 +2,15 @@ class OC_Search_Provider_File extends OC_Search_Provider{ function search($query){ - $files=OC_Filesystem::search($query); + $files=OC_FileCache::search($query,true); $results=array(); - foreach($files as $file){ - if(OC_Filesystem::is_dir($file)){ + foreach($files as $fileData){ + $file=$fileData['path']; + if($fileData['mime']=='httpd/unix-directory'){ $results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'index.php?dir='.$file ),'Files'); }else{ - $mime=OC_Filesystem::getMimeType($file); - $mimeBase=substr($mime,0,strpos($mime,'/')); + $mime=$fileData['mime']; + $mimeBase=$fileData['mimepart']; switch($mimeBase){ case 'audio': break; |