summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <thomas@roundcube.net>2012-05-14 20:53:51 +0200
committerThomas Bruederli <thomas@roundcube.net>2012-05-14 20:53:51 +0200
commit4f7ab00dfbd9d6c8493988dd517d182accbfd56e (patch)
tree368955ed1e2b3dd1e32240f33d5fc598d6f5d3c0
parente88e20c3fbcf285030d807a304f0404d178772d2 (diff)
Respect all arguments when caching IMAP metadata (#1488475)
-rw-r--r--program/include/rcube_imap.php41
1 files changed, 33 insertions, 8 deletions
diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index 24043c53b..cec0ad807 100644
--- a/program/include/rcube_imap.php
+++ b/program/include/rcube_imap.php
@@ -3398,7 +3398,7 @@ class rcube_imap extends rcube_storage
return false;
}
- $this->clear_cache('mailboxes.metadata.' . $folder);
+ $this->clear_cache($this->metadata_cache_key($folder));
if ($this->get_capability('METADATA') ||
(!strlen($folder) && $this->get_capability('METADATA-SERVER'))
@@ -3432,7 +3432,7 @@ class rcube_imap extends rcube_storage
return false;
}
- $this->clear_cache('mailboxes.metadata.' . $folder);
+ $this->clear_cache($this->metadata_cache_key($folder));
if ($this->get_capability('METADATA') ||
(!strlen($folder) && $this->get_capability('METADATA-SERVER'))
@@ -3467,15 +3467,30 @@ class rcube_imap extends rcube_storage
return null;
}
- $cache_key = 'mailboxes.metadata.' . $folder;
- if ($cached = $this->get_cache($cache_key))
- return $cached;
+ $entries = (array)$entries;
+
+ // check cached data
+ $cache_key = $this->metadata_cache_key($folder);
+ $cached_data = (array)$this->get_cache($cache_key);
+ $cached_result = array();
+ $cached_count = 0;
+ foreach ($entries as $entry_key) {
+ if (isset($cached_data[$folder][$entry_key])) {
+ $cached_result[$folder][$entry_key] = $cached_data[$folder][$entry_key];
+ $cached_count++;
+ }
+ }
+
+ // all requested entries are cached
+ if ($cached_count == count($entries)) {
+ return $cached_result;
+ }
if ($this->get_capability('METADATA') ||
(!strlen($folder) && $this->get_capability('METADATA-SERVER'))
) {
$res = $this->conn->getMetadata($folder, $entries, $options);
- $this->update_cache($cache_key, $res);
+ $this->update_cache($cache_key, array_merge_recursive($cached_data, $res));
return $res;
}
else if ($this->get_capability('ANNOTATEMORE') || $this->get_capability('ANNOTATEMORE2')) {
@@ -3483,7 +3498,7 @@ class rcube_imap extends rcube_storage
$res = array();
// Convert entry names
- foreach ((array)$entries as $entry) {
+ foreach ($entries as $entry) {
list($ent, $attr) = $this->md2annotate($entry);
$queries[$attr][] = $ent;
}
@@ -3495,7 +3510,7 @@ class rcube_imap extends rcube_storage
}
}
- $this->update_cache($cache_key, $res);
+ $this->update_cache($cache_key, array_merge_recursive($cached_data, $res));
return $res;
}
@@ -3504,6 +3519,16 @@ class rcube_imap extends rcube_storage
/**
+ * Helper method to compose the cache key for the given folder metadata
+ */
+ protected function metadata_cache_key($folder)
+ {
+ $suffix = $folder == '' ? '[SERVER]' : (strpos($folder, '*') === false ? $folder : '');
+ return 'mailboxes.metadata.' . $suffix;
+ }
+
+
+ /**
* Converts the METADATA extension entry name into the correct
* entry-attrib names for older ANNOTATEMORE version.
*