Use explicit insert() method to skip delete query when caching a newly created object (updated objects get new msguids and are de-facto new)
This commit is contained in:
parent
5fa593ad99
commit
290d0f113f
2 changed files with 49 additions and 32 deletions
|
@ -202,14 +202,33 @@ class kolab_storage_cache
|
|||
return;
|
||||
}
|
||||
|
||||
// write to cache
|
||||
if ($this->ready) {
|
||||
// remove old entry
|
||||
if ($this->ready) {
|
||||
$this->db->query("DELETE FROM kolab_cache WHERE resource=? AND msguid=? AND type<>?",
|
||||
$this->resource_uri, $msguid, 'lock');
|
||||
}
|
||||
|
||||
// write new object data if not false (wich means deleted)
|
||||
if ($object) {
|
||||
// insert new object data...
|
||||
$this->insert($msguid, $object);
|
||||
}
|
||||
else {
|
||||
// ...or set in-memory cache to false
|
||||
$this->objects[$msguid] = $object;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Insert a cache entry
|
||||
*
|
||||
* @param string Related IMAP message UID
|
||||
* @param mixed Hash array with object properties to save or false to delete the cache entry
|
||||
*/
|
||||
public function insert($msguid, $object)
|
||||
{
|
||||
// write to cache
|
||||
if ($this->ready) {
|
||||
$sql_data = $this->_serialize($object);
|
||||
$objtype = $object['_type'] ? $object['_type'] : $this->folder->type;
|
||||
|
||||
|
@ -237,15 +256,13 @@ class kolab_storage_cache
|
|||
), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// keep a copy in memory for fast access
|
||||
$this->objects[$msguid] = $object;
|
||||
|
||||
if ($object)
|
||||
$this->uid2msg[$object['uid']] = $msguid;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Move an existing cache entry to a new resource
|
||||
*
|
||||
|
|
|
@ -592,7 +592,7 @@ class kolab_storage_folder
|
|||
// update cache with new UID
|
||||
if ($result) {
|
||||
$object['_msguid'] = $result;
|
||||
$this->cache->set($result, $object);
|
||||
$this->cache->insert($result, $object);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue