more improvements for foldersize

This commit is contained in:
Robin Appelman 2011-04-17 18:18:27 +02:00
parent ec7e338704
commit 871a4b3d4a
1 changed files with 13 additions and 17 deletions

View File

@ -478,6 +478,10 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
* @return int size of folder and it's content * @return int size of folder and it's content
*/ */
public function getFolderSize($path){ public function getFolderSize($path){
$path=str_replace('//','/',$path);
if($this->is_dir($path) and substr($path,-1)!='/'){
$path.='/';
}
$query=OC_DB::prepare("SELECT size FROM *PREFIX*foldersize WHERE path=?"); $query=OC_DB::prepare("SELECT size FROM *PREFIX*foldersize WHERE path=?");
$size=$query->execute(array($path))->fetchAll(); $size=$query->execute(array($path))->fetchAll();
if(count($size)>0){// we already the size, just return it if(count($size)>0){// we already the size, just return it
@ -500,26 +504,19 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
if($this->is_dir($path) and substr($path,-1)!='/'){ if($this->is_dir($path) and substr($path,-1)!='/'){
$path.='/'; $path.='/';
} }
error_log("calc: $path");
$size=0; $size=0;
if ($dh = $this->opendir($path)) { if ($dh = $this->opendir($path)) {
$query=OC_DB::prepare("SELECT size FROM *PREFIX*foldersize WHERE path=?");
$hasSize=$query->execute(array($path))->fetchAll();
if(count($hasSize)>0){// yes, update it
$query=OC_DB::prepare("UPDATE *PREFIX*foldersize SET size=? WHERE path=?");
$result=$query->execute(array($size,$path));
$size+=$hasSize[0]['size'];
}else{// no insert it
while (($filename = readdir($dh)) !== false) { while (($filename = readdir($dh)) !== false) {
if($filename!='.' and $filename!='..'){ if($filename!='.' and $filename!='..'){
$subFile=$path.'/'.$filename; $subFile=$path.'/'.$filename;
if($this->is_file($subFile)){ if($this->is_file($subFile)){
$size+=$this->filesize($subFile); $size+=$this->filesize($subFile);
}else{ }else{
$size+=$this->calculateFolderSize($subFile); $size+=$this->getFolderSize($subFile);
} }
} }
} }
if($size>0){
$query=OC_DB::prepare("INSERT INTO *PREFIX*foldersize VALUES(?,?)"); $query=OC_DB::prepare("INSERT INTO *PREFIX*foldersize VALUES(?,?)");
$result=$query->execute(array($path,$size)); $result=$query->execute(array($path,$size));
} }
@ -539,7 +536,6 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
if($this->is_dir($path) and substr($path,-1)!='/'){ if($this->is_dir($path) and substr($path,-1)!='/'){
$path.='/'; $path.='/';
} }
error_log($path);
$query=OC_DB::prepare("DELETE FROM *PREFIX*foldersize WHERE path = ?"); $query=OC_DB::prepare("DELETE FROM *PREFIX*foldersize WHERE path = ?");
$result=$query->execute(array($path)); $result=$query->execute(array($path));
if($path!='/' and $path!=''){ if($path!='/' and $path!=''){