Skip to content
Snippets Groups Projects
Commit e11c5a23 authored by Bart Visscher's avatar Bart Visscher
Browse files

Optimize WebDav access by preloading dav custom properties

parent e905b147
Branches
No related tags found
No related merge requests found
...@@ -85,10 +85,28 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa ...@@ -85,10 +85,28 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
*/ */
public function getChildren() { public function getChildren() {
$nodes = array();
$folder_content = OC_FileCache::getFolderContent($this->path); $folder_content = OC_FileCache::getFolderContent($this->path);
$paths = array();
foreach($folder_content as $info) {
$paths[] = $this->path.'/'.$info['name'];
}
$placeholders = join(',', array_fill(0, count($paths), '?'));
$query = OC_DB::prepare( 'SELECT * FROM *PREFIX*properties WHERE userid = ?' . ' AND propertypath IN ('.$placeholders.')' );
array_unshift($paths, OC_User::getUser()); // prepend userid
$result = $query->execute( $paths );
$properties = array_fill_keys($paths, array());
while($row = $result->fetchRow()) {
$propertypath = $row['propertypath'];
$propertyname = $row['propertyname'];
$propertyvalue = $row['propertyvalue'];
$properties[$propertypath][$propertyname] = $propertyvalue;
}
$nodes = array();
foreach($folder_content as $info) { foreach($folder_content as $info) {
$nodes[] = $this->getChild($info['name'], $info); $node = $this->getChild($info['name'], $info);
$node->setPropertyCache($properties[$this->path.'/'.$info['name']]);
$nodes[] = $node;
} }
return $nodes; return $nodes;
} }
......
...@@ -30,10 +30,15 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr ...@@ -30,10 +30,15 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
*/ */
protected $path; protected $path;
/** /**
* file stat cache * node fileinfo cache
* @var array * @var array
*/ */
protected $fileinfo_cache; protected $fileinfo_cache;
/**
* node properties cache
* @var array
*/
protected $property_cache = null;
/** /**
* Sets up the node, expects a full path name * Sets up the node, expects a full path name
...@@ -101,6 +106,11 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr ...@@ -101,6 +106,11 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
} }
} }
public function setPropertyCache($property_cache)
{
$this->property_cache = $property_cache;
}
/** /**
* Returns the last modification time, as a unix timestamp * Returns the last modification time, as a unix timestamp
* *
...@@ -153,6 +163,7 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr ...@@ -153,6 +163,7 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
} }
} }
$this->setPropertyCache(null);
return true; return true;
} }
...@@ -168,23 +179,24 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr ...@@ -168,23 +179,24 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
* @return void * @return void
*/ */
function getProperties($properties) { function getProperties($properties) {
// At least some magic in here :-) if (is_null($this->property_cache)) {
$query = OC_DB::prepare( 'SELECT * FROM *PREFIX*properties WHERE userid = ? AND propertypath = ?' ); $query = OC_DB::prepare( 'SELECT * FROM *PREFIX*properties WHERE userid = ? AND propertypath = ?' );
$result = $query->execute( array( OC_User::getUser(), $this->path )); $result = $query->execute( array( OC_User::getUser(), $this->path ));
$existing = array(); $this->property_cache = array();
while( $row = $result->fetchRow()){ while( $row = $result->fetchRow()){
$existing[$row['propertyname']] = $row['propertyvalue']; $this->property_cache[$row['propertyname']] = $row['propertyvalue'];
}
} }
// if the array was empty, we need to return everything // if the array was empty, we need to return everything
if(count($properties) == 0){ if(count($properties) == 0){
return $existing; return $this->property_cache;
} }
$props = array(); $props = array();
foreach($properties as $property) { foreach($properties as $property) {
if (isset($existing[$property])) $props[$property] = $existing[$property]; if (isset($this->property_cache[$property])) $props[$property] = $this->property_cache[$property];
} }
return $props; return $props;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment