Post-filter all tag objects (in case caching is disabled); improve kolab_storage_cache for the case caching is off

This commit is contained in:
Thomas Bruederli 2014-08-26 12:03:11 +02:00
parent 43d3f85448
commit 54b6eb66de
3 changed files with 36 additions and 7 deletions

View file

@ -265,8 +265,10 @@ class kolab_storage_cache
// fetch from IMAP if not present in cache
if (empty($this->objects[$msguid])) {
$result = $this->_fetch(array($msguid), $type, $foldername);
$this->objects = array($msguid => $result[0]); // store only this object in memory (#2827)
if ($object = $this->folder->read_object($msguid, $type ?: '*', $foldername)) {
$this->objects = array($msguid => $object);
$this->set($msguid, $object);
}
}
}

View file

@ -38,6 +38,28 @@ class kolab_storage_cache_configuration extends kolab_storage_cache
return $sql_data;
}
/**
* Select Kolab objects filtered by the given query
*
* @param array Pseudo-SQL query as list of filter parameter triplets
* @param boolean Set true to only return UIDs instead of complete objects
* @return array List of Kolab data objects (each represented as hash array) or UIDs
*/
public function select($query = array(), $uids = false)
{
// modify query for IMAP search: query param 'type' is actually a subtype
if (!$this->ready) {
foreach ($query as $i => $tuple) {
if ($tuple[0] == 'type') {
$tuple[2] = 'configuration.' . $tuple[2];
$query[$i] = $tuple;
}
}
}
return parent::select($query, $uids);
}
/**
* Helper method to compose a valid SQL query from pseudo filter triplets
*/

View file

@ -125,6 +125,7 @@ class kolab_storage_config
}
foreach ($folder->select($filter) as $object) {
unset($object['_formatobj']);
$list[] = $object;
}
}
@ -626,20 +627,24 @@ class kolab_storage_config
// use faster method
if ($uid && $uid != '*') {
$filter[] = array('member', '=', $uid);
return $this->get_objects($filter, $default);
$tags = $this->get_objects($filter, $default);
}
$this->tags = $this->get_objects($filter, $default);
else {
$this->tags = $tags = $this->get_objects($filter, $default);
}
}
else {
$tags = $this->tags;
}
if ($uid === '*') {
return $this->tags;
return $tags;
}
$result = array();
$search = self::build_member_url($uid);
foreach ($this->tags as $tag) {
foreach ($tags as $tag) {
if (in_array($search, (array) $tag['members'])) {
$result[] = $tag;
}