Skip to content

Commit

Permalink
Cache mailbox search results, and honor the <rebuildresults/> flag.
Browse files Browse the repository at this point in the history
No longer hit the IMAP server when paging mailbox search results.
  • Loading branch information
mrubinsk committed Jan 4, 2014
1 parent 3a4f538 commit 12569e8
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions framework/Core/lib/Horde/Core/ActiveSync/Driver.php
Expand Up @@ -1691,25 +1691,45 @@ public function changeMessage($folderid, $id, Horde_ActiveSync_Message_Base $mes
*
* @param string $type The search type; ['gal'|'mailbox']
* @param array $query The search query. An array containing:
* - query: array The search query. Contains at least:
* 'query' and 'range'. The rest depends on the type of
* search being performed.
* DEFAULT: none, REQUIRED
* - range: (string) A range limiter.
* DEFAULT: none (No range used).
* - query: (array) The search query. Contains at least:
* 'query' and 'range'. The rest depends on the type of
* search being performed.
* DEFAULT: none, REQUIRED
* - range: (string) A range limiter.
* DEFAULT: none (No range used).
* - rebuildresults: (boolean) If true, invalidate any cached search.
* DEFAULT: Use cached search results if available.
* - deeptraversal: (boolean) If true, traverse sub folders.
* @todo NOT IMPLEMENTED YET.
*
* @return array An array containing:
* - rows: An array of search results
* - rows: An array of search results, limited by $query['range'].
* - status: The search store status code.
* - total: The total number of matches (for mailbox searches).
* - total: The total number of matches (not limited by $query['range']
*/
public function getSearchResults($type, array $query)
{
switch (strtolower($type)) {
case 'gal':
return $this->_searchGal($query);
case 'mailbox':
$results = $this->_searchMailbox($query);
if (!empty($this->_cache)) {
$clear_cache = !empty($query['rebuildresults']);
unset($query['rebuildresults']);
$cache_key = $GLOBALS['registry']->getAuth() . ':HCASD:' . md5(serialize($query['rebuildresults']));
if ($clear_cache) {
$this->_cache->expire($cache_key);
}
}
if (!empty($this->_cache) && $this->_cache->exists($cache_key, 0)) {
$results = json_decode($this->_cache->get($cache_key, 0), true);
} else {
$results = $this->_searchMailbox($query);
if (!empty($this->_cache)) {
$this->_cache->set($cache_key, json_encode($results));
}
}

$count = count($results);
if (!empty($query['range'])) {
$range = explode('-', $query['range']);
Expand Down

0 comments on commit 12569e8

Please sign in to comment.