|
|
|
|
@ -28,6 +28,8 @@ |
|
|
|
|
* It will try to keep the data up to date but changes from outside ownCloud can invalidate the cache |
|
|
|
|
*/ |
|
|
|
|
class OC_FileCache{ |
|
|
|
|
private static $savedData=array(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* get the filesystem info from the cache |
|
|
|
|
* @param string path |
|
|
|
|
@ -93,6 +95,14 @@ class OC_FileCache{ |
|
|
|
|
self::update($id,$data); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if(isset(self::$savedData[$path])){ |
|
|
|
|
$data=array_merge($data,self::$savedData[$path]); |
|
|
|
|
unset(self::$savedData[$path]); |
|
|
|
|
} |
|
|
|
|
if(!isset($data['size']) or !isset($data['mtime'])){//save incomplete data for the next time we write it |
|
|
|
|
self::$savedData[$path]=$data; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if(!isset($data['encrypted'])){ |
|
|
|
|
$data['encrypted']=false; |
|
|
|
|
} |
|
|
|
|
@ -101,9 +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) VALUES(?,?,?,?,?,?,?,?,?,?)'); |
|
|
|
|
$query->execute(array($parent,basename($path),$path,$data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart,$user,$data['writable'])); |
|
|
|
|
|
|
|
|
|
$query=OC_DB::prepare('INSERT INTO *PREFIX*fscache(parent, name, path, size, mtime, ctime, mimetype, mimepart,user,writable,encrypted,versioned) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)'); |
|
|
|
|
$query->execute(array($parent,basename($path),$path,$data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart,$user,$data['writable'],$data['encrypted'],$data['versioned'])); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -323,7 +332,29 @@ class OC_FileCache{ |
|
|
|
|
} |
|
|
|
|
self::increaseSize(dirname($fullPath),$size-$cachedSize); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static function getCached($path,$root=''){ |
|
|
|
|
if(!$root){ |
|
|
|
|
$root=OC_Filesystem::getRoot(); |
|
|
|
|
}else{ |
|
|
|
|
if($root=='/'){ |
|
|
|
|
$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(); |
|
|
|
|
if(is_array($result)){ |
|
|
|
|
if(isset(self::$savedData[$path])){ |
|
|
|
|
$result=array_merge($result,self::$savedData[$path]); |
|
|
|
|
} |
|
|
|
|
return $result; |
|
|
|
|
}else{ |
|
|
|
|
OC_Log::write('get(): file not found in cache ('.$path.')','core',OC_Log::DEBUG); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static function getCachedSize($path,$root){ |
|
|
|
|
if(!$root){ |
|
|
|
|
$root=OC_Filesystem::getRoot(); |
|
|
|
|
@ -332,6 +363,7 @@ class OC_FileCache{ |
|
|
|
|
$root=''; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$path=$root.$path; |
|
|
|
|
$query=OC_DB::prepare('SELECT size FROM *PREFIX*fscache WHERE path=?'); |
|
|
|
|
$result=$query->execute(array($path)); |
|
|
|
|
if($row=$result->fetchRow()){ |
|
|
|
|
|