Query kolab_cache_configuration with category filter for better performance (#3286)

Warning: this requires DELETE FROM kolab_folders WHERE type = 'configuration';
This commit is contained in:
Aleksander Machniak 2014-08-19 05:10:31 -04:00
parent afed2435d7
commit e3d29617ae
6 changed files with 49 additions and 26 deletions

View file

@ -1109,11 +1109,13 @@ class kolab_notes extends rcube_plugin
{ {
if (!isset($this->relations)) { if (!isset($this->relations)) {
$config = kolab_storage_config::get_instance(); $config = kolab_storage_config::get_instance();
$filter = array(array('type', '=', 'relation'));
$default = true; $default = true;
$data_filter = array('category' => 'generic'); $filter = array(
array('type', '=', 'relation'),
array('category', '=', 'generic')
);
$this->relations = $config->get_objects($filter, $default, $data_filter); $this->relations = $config->get_objects($filter, $default);
} }
if ($uid === null) { if ($uid === null) {

View file

@ -293,7 +293,7 @@ function tag_form_dialog(id)
if (tag) { if (tag) {
name_input.val(tag.name); name_input.val(tag.name);
color_input.val(tag.color.replace(/^#/, '')); color_input.val(tag.color ? tag.color.replace(/^#/, '') : '');
} }
} }

View file

@ -38,14 +38,14 @@ class kolab_tags_backend
*/ */
public function list_tags($filter = array()) public function list_tags($filter = array())
{ {
$config = kolab_storage_config::get_instance(); $config = kolab_storage_config::get_instance();
$default = true; $default = true;
$filter[] = array('type', '=', self::O_TYPE); $filter[] = array('type', '=', self::O_TYPE);
$cat_filter = array('category' => self::O_CATEGORY); $filter[] = array('category', '=', self::O_CATEGORY);
// for performance reasons assume there will be no more than 100 tags (per-folder) // for performance reasons assume there will be no more than 100 tags (per-folder)
return $config->get_objects($filter, $default, $cat_filter, 100); return $config->get_objects($filter, $default, 100);
} }
/** /**

View file

@ -208,8 +208,14 @@ class kolab_format_configuration extends kolab_format
{ {
$tags = array(); $tags = array();
if ($this->data['type'] == 'dictionary') { switch ($this->data['type']) {
case 'dictionary':
$tags = array($this->data['language']); $tags = array($this->data['language']);
break;
case 'relation':
$tags = array('category:' . $this->data['category']);
break;
} }
return $tags; return $tags;

View file

@ -37,4 +37,24 @@ class kolab_storage_cache_configuration extends kolab_storage_cache
return $sql_data; return $sql_data;
} }
}
/**
* Helper method to compose a valid SQL query from pseudo filter triplets
*/
protected function _sql_where($query)
{
if (is_array($query)) {
foreach ($query as $idx => $param) {
// convert category filter
if ($param[0] == 'category') {
$param[2] = array_map(function($n) { return 'category:' . $n; }, (array) $param[2]);
$query[$idx][0] = 'tags';
$query[$idx][2] = count($param[2]) > 1 ? $param[2] : $param[2][0];
}
}
}
return parent::_sql_where($query);
}
}

View file

@ -103,14 +103,13 @@ class kolab_storage_config
/** /**
* Get configuration objects * Get configuration objects
* *
* @param array $filter Search filter * @param array $filter Search filter
* @param bool $default Enable to get objects only from default folder * @param bool $default Enable to get objects only from default folder
* @param array $data_filter Additional object data filter * @param int $limit Max. number of records (per-folder)
* @param int $limit Max. number of records (per-folder)
* *
* @return array List of objects * @return array List of objects
*/ */
public function get_objects($filter = array(), $default = false, $data_filter = array(), $limit = 0) public function get_objects($filter = array(), $default = false, $limit = 0)
{ {
$list = array(); $list = array();
@ -126,12 +125,6 @@ class kolab_storage_config
} }
foreach ($folder->select($filter) as $object) { foreach ($folder->select($filter) as $object) {
foreach ($data_filter as $key => $val) {
if ($object[$key] != $val) {
continue 2;
}
}
$list[] = $object; $list[] = $object;
} }
} }
@ -624,11 +617,13 @@ class kolab_storage_config
public function get_tags($uid = '*') public function get_tags($uid = '*')
{ {
if (!isset($this->tags)) { if (!isset($this->tags)) {
$filter = array(array('type', '=', 'relation')); $default = true;
$default = true; $filter = array(
$data_filter = array('category' => 'tag'); array('type', '=', 'relation'),
array('category', '=', 'tag')
);
$this->tags = $this->get_objects($filter, $default, $data_filter); $this->tags = $this->get_objects($filter, $default);
} }
if ($uid === '*') { if ($uid === '*') {