Improve fetching contacts with new kolab_storage/cache backend

This commit is contained in:
Thomas Bruederli 2012-05-16 10:49:53 +02:00
parent 3a1f2c207c
commit c3cfc084a7
2 changed files with 18 additions and 5 deletions

View file

@ -246,13 +246,12 @@ class rcube_kolab_contacts extends rcube_addressbook
*/ */
public function list_records($cols=null, $subset=0) public function list_records($cols=null, $subset=0)
{ {
$this->result = $this->count(); $this->result = new rcube_result_set(0, ($this->list_page-1) * $this->page_size);;
// list member of the selected group // list member of the selected group
if ($this->gid) { if ($this->gid) {
$this->_fetch_groups(); $this->_fetch_groups();
$seen = array(); $seen = array();
$this->result->count = 0;
foreach ((array)$this->distlists[$this->gid]['member'] as $member) { foreach ((array)$this->distlists[$this->gid]['member'] as $member) {
// skip member that don't match the search filter // skip member that don't match the search filter
if (is_array($this->filter['ids']) && array_search($member['ID'], $this->filter['ids']) === false) if (is_array($this->filter['ids']) && array_search($member['ID'], $this->filter['ids']) === false)
@ -269,9 +268,15 @@ class rcube_kolab_contacts extends rcube_addressbook
} }
$ids = array_keys($seen); $ids = array_keys($seen);
} }
else if (is_array($this->filter['ids'])) {
$ids = $this->filter['ids'];
if ($this->result->count = count($ids))
$this->_fetch_contacts(array(array('uid', '=', $ids)));
}
else { else {
$this->_fetch_contacts(); $this->_fetch_contacts();
$ids = is_array($this->filter['ids']) ? $this->filter['ids'] : array_keys($this->contacts); $ids = array_keys($this->contacts);
$this->result->count = count($ids);
} }
// sort data arrays according to desired list sorting // sort data arrays according to desired list sorting

View file

@ -326,7 +326,7 @@ class kolab_storage_cache
/** /**
* Get number of objects mathing the given query * Get number of objects mathing the given query
* *
* @param string $type Object type (e.g. contact, event, todo, journal, note, configuration) * @param array $query Pseudo-SQL query as list of filter parameter triplets
* @return integer The number of objects of the given type * @return integer The number of objects of the given type
*/ */
public function count($query = array()) public function count($query = array())
@ -363,10 +363,18 @@ class kolab_storage_cache
{ {
$sql_where = ''; $sql_where = '';
foreach ($query as $param) { foreach ($query as $param) {
if ($param[1] == '=' && is_array($param[2])) {
$qvalue = '(' . join(',', array_map(array($this->db, 'quote'), $param[2])) . ')';
$param[1] = 'IN';
}
else {
$qvalue = $this->db->quote($param[2]);
}
$sql_where .= sprintf(' AND %s %s %s', $sql_where .= sprintf(' AND %s %s %s',
$this->db->quote_identifier($param[0]), $this->db->quote_identifier($param[0]),
$param[1], $param[1],
$this->db->quote($param[2]) $qvalue
); );
} }