From: Robin Appelman Date: Sun, 29 Apr 2012 14:11:17 +0000 (+0200) Subject: improve rescanning folders X-Git-Tag: v4.0.0beta~154 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4d3ef9a82448da91335059c8c0ae14e46ecbd18a;p=nextcloud-server.git improve rescanning folders --- diff --git a/lib/filecache.php b/lib/filecache.php index 431470696a6..fce9785f745 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -522,30 +522,27 @@ class OC_FileCache{ $view=new OC_FilesystemView(($root=='/')?'':$root); } self::scanFile($path,$root); - if(self::inCache($path)){ - self::updateFolder($path,$root); - }else{ - $dh=$view->opendir($path.'/'); - $totalSize=0; - if($dh){ - while (($filename = readdir($dh)) !== false) { - if($filename != '.' and $filename != '..'){ - $file=$path.'/'.$filename; - if($view->is_dir($file.'/')){ - self::scan($file,$eventSource,$count,$root); - }else{ - $totalSize+=self::scanFile($file,$root); - $count++; - if($count>$lastSend+25 and $eventSource){ - $lastSend=$count; - $eventSource->send('scanning',array('file'=>$path,'count'=>$count)); - } + $dh=$view->opendir($path.'/'); + $totalSize=0; + if($dh){ + while (($filename = readdir($dh)) !== false) { + if($filename != '.' and $filename != '..'){ + $file=$path.'/'.$filename; + if($view->is_dir($file.'/')){ + self::scan($file,$eventSource,$count,$root); + }else{ + $totalSize+=self::scanFile($file,$root); + $count++; + if($count>$lastSend+25 and $eventSource){ + $lastSend=$count; + $eventSource->send('scanning',array('file'=>$path,'count'=>$count)); } } } } - self::increaseSize($view->getRoot().$path,$totalSize); } + self::cleanFolder($path,$root); + self::increaseSize($view->getRoot().$path,$totalSize); } /** @@ -668,7 +665,26 @@ class OC_FileCache{ } } } + + self::cleanFolder($path,$root); + + //update the folder last, so we can calculate the size correctly + if(!$root){//filesystem hooks are only valid for the default root + OC_Hook::emit('OC_Filesystem','post_write',array('path'=>$path)); + }else{ + self::fileSystemWatcherWrite(array('path'=>$path),$root); + } + } + /** + * delete non existing files from the cache + */ + private static function cleanFolder($path,$root=''){ + if(!$root){ + $view=OC_Filesystem::getView(); + }else{ + $view=new OC_FilesystemView(($root=='/')?'':$root); + } //check for removed files, not using getFolderContent to prevent loops $parent=self::getFileId($view->getRoot().$path); $query=OC_DB::prepare('SELECT name FROM *PREFIX*fscache WHERE parent=?'); @@ -683,12 +699,6 @@ class OC_FileCache{ } } } - //update the folder last, so we can calculate the size correctly - if(!$root){//filesystem hooks are only valid for the default root - OC_Hook::emit('OC_Filesystem','post_write',array('path'=>$path)); - }else{ - self::fileSystemWatcherWrite(array('path'=>$path),$root); - } } /**