Skip to content

Commit

Permalink
Various fixes to hashtable driver
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Jan 3, 2014
1 parent 6b8dd1f commit bfa5c9b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion framework/Imap_Client/doc/Horde/Imap/Client/UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This lists the API changes between releases of the package.
Upgrading to 2.17.0
===================

- Horde_Imap_Client_Cache_Hashtable
- Horde_Imap_Client_Cache_Backend_Hashtable

Added a Hashtable specific caching driver.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
* @package Imap_Client
* @since 2.17.0
*/
class Horde_Imap_Client_Cache_Hashtable extends Horde_Imap_Client_Cache_Backend
class Horde_Imap_Client_Cache_Backend_Hashtable
extends Horde_Imap_Client_Cache_Backend
{
/**/
/** Separator for CID between mailbox and UID. */
const CID_SEPARATOR = '|';

/**
* The working data for the current pageload. All changes take place to
* The working data for the current pageload. All changes take place to
* this data.
*
* @var array
Expand Down Expand Up @@ -158,22 +159,29 @@ public function set($mailbox, $data, $uidvalid)
$this->_loadUids($mailbox, array_keys($data), $uidvalid);

$d = &$this->_data[$mailbox];
$to_add = array();

foreach ($data as $k => $v) {
if (isset($d[$k]) && is_string($d[$k])) {
try {
$d[$k] = $this->_pack->unpack($d[$k]);
} catch (Horde_Pack_Exception $e) {}
} catch (Horde_Pack_Exception $e) {
continue;
}
}

$d[$k] = (isset($d[$k]) && is_array($d[$k]))
? array_merge($d[$k], $v)
: $v;
$this->_update[$mailbox]['u'][$k] = true;
unset($this->_update[$mailbox]['d'][$k]);
$to_add[] = $k;
}

$this->_mbox[$mailbox]['u']->add(array_keys($data));
if (!empty($to_add)) {
$this->_mbox[$mailbox]['u']->add($to_add);
$this->_update[$mailbox]['m'] = true;
}
}

/**
Expand All @@ -183,7 +191,7 @@ public function getMetaData($mailbox, $uidvalid, $entries)
$this->_loadMailbox($mailbox, $uidvalid);

return empty($entries)
? $this->_mbox[$mailbox]
? $this->_mbox[$mailbox]['d']
: array_intersect_key($this->_mbox[$mailbox]['d'], array_flip($entries));
}

Expand Down Expand Up @@ -215,6 +223,7 @@ public function deleteMsgs($mailbox, $uids)
}

$this->_mbox[$mailbox]['u']->remove($uids);
$this->_update[$mailbox]['m'] = true;
}

/**
Expand All @@ -226,8 +235,8 @@ public function deleteMailbox($mailbox)
$this->_loadMailbox($mailbox);

$this->_hash->delete(array_merge(
$this->_getCid($mailbox),
$this->_getMsgCids($mailbox, $this->_mbox[$mailbox]['u'])
array($this->_getCid($mailbox)),
array_values($this->_getMsgCids($mailbox, $this->_mbox[$mailbox]['u']))
));

unset(
Expand Down Expand Up @@ -256,8 +265,8 @@ public function save()
{
foreach ($this->_update as $mbox => $val) {
if (!empty($val['u'])) {
$ptr = &$this->_mbox[$mbox];
foreach ($this->_getMsgCids($mbox, $val['u']) as $k2 => $v2) {
$ptr = &$this->_data[$mbox];
foreach ($this->_getMsgCids($mbox, array_keys($val['u'])) as $k2 => $v2) {
try {
$this->_hash->set($v2, $this->_pack->pack($ptr[$k2]));
} catch (Horde_Pack_Exception $e) {
Expand Down Expand Up @@ -339,12 +348,17 @@ protected function _loadUids($mailbox, $uids, $uidvalid = null)

$ptr = &$this->_data[$mailbox];

$load = array_flip($this->_getMsgCids(
$mailbox,
array_unique(array_diff($this->_mbox[$mailbox]['u']->ids, $uids))
));
$load = array_flip(
array_diff_key(
$this->_getMsgCids(
$mailbox,
array_unique(array_intersect($this->_mbox[$mailbox]['u']->ids, $uids))
),
$this->_data[$mailbox]
)
);

foreach (array_filter($this->_hash->get(array_keys($cid))) as $key => $val) {
foreach (array_filter($this->_hash->get(array_keys($load))) as $key => $val) {
$ptr[$load[$key]] = $val;
}
}
Expand Down

0 comments on commit bfa5c9b

Please sign in to comment.