Fast-mode for configuration objects

This commit is contained in:
Aleksander Machniak 2018-12-24 10:45:19 +00:00
parent a90d4c6015
commit c9499eeaa6
4 changed files with 54 additions and 6 deletions

View file

@ -32,20 +32,37 @@ class kolab_storage_cache_configuration extends kolab_storage_cache
*/
protected function _serialize($object)
{
$this->set_data_props($object['type']);
$sql_data = parent::_serialize($object);
$sql_data['type'] = $object['type'];
return $sql_data;
}
/**
* Helper method to convert database record to the given Kolab object
*
* @override
*/
protected function _unserialize($sql_arr)
{
$this->set_data_props($sql_arr['type']);
return parent::_unserialize($sql_arr);
}
/**
* Select Kolab objects filtered by the given query
*
* @param array Pseudo-SQL query as list of filter parameter triplets
* @param array Pseudo-SQL query as list of filter parameter triplets
* @param boolean Set true to only return UIDs instead of complete objects
* @param boolean Use fast mode to fetch only minimal set of information
* (no xml fetching and parsing, etc.)
*
* @return array List of Kolab data objects (each represented as hash array) or UIDs
*/
public function select($query = array(), $uids = false)
public function select($query = array(), $uids = false, $fast = false)
{
// modify query for IMAP search: query param 'type' is actually a subtype
if (!$this->ready) {
@ -57,7 +74,7 @@ class kolab_storage_cache_configuration extends kolab_storage_cache
}
}
return parent::select($query, $uids);
return parent::select($query, $uids, $fast);
}
/**
@ -85,4 +102,35 @@ class kolab_storage_cache_configuration extends kolab_storage_cache
return parent::_sql_where($query);
}
/**
* Set $data_props property depending on object type
*/
protected function set_data_props($type)
{
switch ($type) {
case 'dictionary':
$this->data_props = array('language', 'e');
break;
case 'file_driver':
$this->data_props = array('driver', 'title', 'enabled', 'host', 'port', 'username', 'password');
break;
case 'relation':
// Note: Because relations are heavily used, for performance reasons
// we store all properties for them
$this->data_props = array('name', 'category', 'color', 'parent', 'iconName', 'priority', 'members');
break;
case 'snippet':
$this->data_props = array('name');
break;
case 'category':
default:
// TODO: implement this
$this->data_props = array();
}
}
}

View file

@ -70,4 +70,4 @@ class kolab_storage_cache_contact extends kolab_storage_cache
return $sql_data;
}
}
}

View file

@ -24,4 +24,4 @@
class kolab_storage_cache_note extends kolab_storage_cache
{
protected $data_props = array('title');
}
}

View file

@ -131,7 +131,7 @@ class kolab_storage_config
$folder->set_order_and_limit(null, $limit);
}
foreach ($folder->select($filter) as $object) {
foreach ($folder->select($filter, true) as $object) {
unset($object['_formatobj']);
$list[] = $object;
}