Skip to content

Commit

Permalink
[jan] Optimize deleting or moving a large number of messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Aug 5, 2016
1 parent 0cb25f4 commit ed3972e
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 20 deletions.
1 change: 1 addition & 0 deletions imp/docs/CHANGES
Expand Up @@ -2,6 +2,7 @@
v6.2.16-git
-----------

[jan] Optimize deleting or moving a large number of messages.
[jan] Fix the 'special_mboxes' backend configuration (Bug #14423).
[mjr] Fix display of applicatoin/pkcs-7-mime parts (Bug #14363).

Expand Down
5 changes: 3 additions & 2 deletions imp/lib/Maillog.php
Expand Up @@ -69,9 +69,10 @@ public function getLog(IMP_Maillog_Message $msg, array $filter = array())
/**
* Delete log entries.
*
* @param array $msgs An array of message objects to delete.
* @param IMP_Maillog_Messages|array $msgs A list of message objects to
* delete.
*/
public function deleteLog(array $msgs)
public function deleteLog($msgs)
{
$this->storage->deleteLogs($msgs);
}
Expand Down
89 changes: 89 additions & 0 deletions imp/lib/Maillog/Messages.php
@@ -0,0 +1,89 @@
<?php
/**
* Copyright 2014-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @category Horde
* @copyright 2014-2016 Horde LLC
* @license http://www.horde.org/licenses/gpl GPL
* @package IMP
*/

/**
* Object representing a series of logged messages.
*
* @author Michael Slusarz <slusarz@horde.org>
* @author Jan Schneider <jan@horde.org>
* @category Horde
* @copyright 2014-2016 Horde LLC
* @license http://www.horde.org/licenses/gpl GPL
* @package IMP
*/
class IMP_Maillog_Messages implements IteratorAggregate
{
/**
* The messages' mailbox.
*
* @var IMP_Mailbox
*/
protected $_mbox;

/**
* IDs of the messages.
*
* @var Horde_Imap_Client_Ids
*/
protected $_ids;

/**
* Message-IDs.
*
* @var array
*/
protected $_msgids;

/**
* Constructor.
*
* @param IMP_Mailbox $mbox The messages' mailbox.
* @param Horde_Imap_Client_Ids $data IDs of the messages.
*/
public function __construct(IMP_Mailbox $mbox, Horde_Imap_Client_Ids $data)
{
$this->_mbox = $mbox;
$this->_ids = $data;
}

/**
*/
public function getMessageIds()
{
if (isset($this->_msgids)) {
return $this->_msgids;
}

$this->_msgids = array();
$query = new Horde_Imap_Client_Fetch_Query();
$query->envelope();
$ret = $this->_mbox->imp_imap->fetch(
$this->_mbox,
$query,
array('ids' => $this->_ids)
);
foreach ($ret as $ob) {
$this->_msgids[] = $ob->getEnvelope()->message_id;
}
Horde::debug($this->_msgids);

return $this->_msgids;
}

/* Iterator methods. */

public function getIterator()
{
return new ArrayIterator($this->getMessageIds());
}
}
5 changes: 3 additions & 2 deletions imp/lib/Maillog/Storage/Base.php
Expand Up @@ -49,9 +49,10 @@ abstract public function getLog(
/**
* Delete log entries.
*
* @param array $msgs Message objects (IMP_Maillog_Message objects).
* @param IMP_Maillog_Messages|array $msgs Message objects
* (IMP_Maillog_Message objects).
*/
abstract public function deleteLogs(array $msgs);
abstract public function deleteLogs($msgs);

/**
* Retrieve changes to the maillog since the provided timestamp.
Expand Down
2 changes: 1 addition & 1 deletion imp/lib/Maillog/Storage/Composite.php
Expand Up @@ -69,7 +69,7 @@ public function getLog(IMP_Maillog_Message $msg, array $filter = array())

/**
*/
public function deleteLogs(array $msgs)
public function deleteLogs($msgs)
{
foreach ($this->_drivers as $val) {
$val->deleteLogs($msgs);
Expand Down
10 changes: 6 additions & 4 deletions imp/lib/Maillog/Storage/History.php
Expand Up @@ -144,7 +144,7 @@ public function getLog(IMP_Maillog_Message $msg, array $filter = array())

/**
*/
public function deleteLogs(array $msgs)
public function deleteLogs($msgs)
{
$ids = array();
foreach ($msgs as $val) {
Expand Down Expand Up @@ -184,15 +184,17 @@ public function getChanges($ts)
/**
* Generate the unique log ID for an event.
*
* @param mixed $msg An IMP_Maillog_Message object or, if null, return
* the parent ID.
* @param mixed $msg An IMP_Maillog_Message object, a Message-ID, or, if
* null, return the parent ID.
*
* @return string The unique log ID.
* @throws RuntimeException
*/
protected function _getUniqueHistoryId($msg = null)
{
$msgid = $msg ? $msg->msgid : null;
$msgid = $msg
? (is_string($msg) ? $msg : $msg->msgid)
: null;
if ($msgid === '') {
throw new RuntimeException('Message-ID missing.');
}
Expand Down
2 changes: 1 addition & 1 deletion imp/lib/Maillog/Storage/Mdnsent.php
Expand Up @@ -82,7 +82,7 @@ public function getLog(IMP_Maillog_Message $msg, array $filter = array())

/**
*/
public function deleteLogs(array $msgs)
public function deleteLogs($msgs)
{
/* Deleting a message takes care of this. */
}
Expand Down
2 changes: 1 addition & 1 deletion imp/lib/Maillog/Storage/Null.php
Expand Up @@ -40,7 +40,7 @@ public function getLog(IMP_Maillog_Message $msg, array $filter = array())

/**
*/
public function deleteLogs(array $msgs)
public function deleteLogs($msgs)
{
}

Expand Down
8 changes: 1 addition & 7 deletions imp/lib/Message.php
Expand Up @@ -251,13 +251,7 @@ public function delete(IMP_Indices $indices, array $opts = array())
* don't care about this data and 2) message IDs (used by some
* maillog backends) won't be available after deletion. */
if ($maillog) {
$delete_ids = array();
foreach ($ids_ob as $val) {
$delete_ids[] = new IMP_Maillog_Message(
new IMP_Indices($ob->mbox, $val)
);
}
$maillog->deleteLog($delete_ids);
$maillog->deleteLog(new IMP_Maillog_Messages($ob->mbox, $ids_ob));
}

/* Delete the messages. */
Expand Down
8 changes: 6 additions & 2 deletions imp/package.xml
Expand Up @@ -22,7 +22,7 @@
<email>chuck@horde.org</email>
<active>no</active>
</lead>
<date>2016-07-01</date>
<date>2016-07-28</date>
<version>
<release>6.2.16</release>
<api>6.2.0</api>
Expand All @@ -33,6 +33,7 @@
</stability>
<license uri="http://www.horde.org/licenses/gpl">GPL-2.0</license>
<notes>
* [jan] Optimize deleting or moving a large number of messages.
* [jan] Fix the &apos;special_mboxes&apos; backend configuration (Bug #14423).
* [mjr] Fix display of applicatoin/pkcs-7-mime parts (Bug #14363).
</notes>
Expand Down Expand Up @@ -377,6 +378,7 @@
<file name="Null.php" role="horde" />
</dir> <!-- /lib/Maillog/Storage -->
<file name="Message.php" role="horde" />
<file name="Messages.php" role="horde" />
</dir> <!-- /lib/Maillog -->
<dir name="Mbox">
<file name="Generate.php" role="horde" />
Expand Down Expand Up @@ -1773,6 +1775,7 @@
<install as="imp/lib/Mailbox/List/Thread.php" name="lib/Mailbox/List/Thread.php" />
<install as="imp/lib/Mailbox/List/Virtual.php" name="lib/Mailbox/List/Virtual.php" />
<install as="imp/lib/Maillog/Message.php" name="lib/Maillog/Message.php" />
<install as="imp/lib/Maillog/Messages.php" name="lib/Maillog/Messages.php" />
<install as="imp/lib/Maillog/Log/Base.php" name="lib/Maillog/Log/Base.php" />
<install as="imp/lib/Maillog/Log/Forward.php" name="lib/Maillog/Log/Forward.php" />
<install as="imp/lib/Maillog/Log/Mdn.php" name="lib/Maillog/Log/Mdn.php" />
Expand Down Expand Up @@ -3960,9 +3963,10 @@
<stability>
<release>stable</release>
<api>stable</api></stability>
<date>2016-07-01</date>
<date>2016-07-28</date>
<license uri="http://www.horde.org/licenses/gpl">GPL-2.0</license>
<notes>
* [jan] Optimize deleting or moving a large number of messages.
* [jan] Fix the &apos;special_mboxes&apos; backend configuration (Bug #14423).
* [mjr] Fix display of applicatoin/pkcs-7-mime parts (Bug #14363).
</notes>
Expand Down

0 comments on commit ed3972e

Please sign in to comment.