mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-09 06:28:28 +03:00
Speedup MessageListByRequestIndexOrUids() by using the new FetchIterate()
This commit is contained in:
parent
fe718e81e9
commit
c8deecb4aa
2 changed files with 28 additions and 23 deletions
|
|
@ -32,7 +32,7 @@ trait Messages
|
|||
* @throws \MailSo\Net\Exceptions\*
|
||||
* @throws \MailSo\Imap\Exceptions\*
|
||||
*/
|
||||
public function Fetch(array $aInputFetchItems, string $sIndexRange, bool $bIndexIsUid) : array
|
||||
public function FetchIterate(array $aInputFetchItems, string $sIndexRange, bool $bIndexIsUid) : iterable
|
||||
{
|
||||
if (!\strlen(\trim($sIndexRange))) {
|
||||
$this->writeLogException(new \InvalidArgumentException, \LOG_ERR);
|
||||
|
|
@ -112,7 +112,7 @@ trait Messages
|
|||
foreach ($this->yieldUntaggedResponses() as $oResponse) {
|
||||
if (FetchResponse::isValidImapResponse($oResponse)) {
|
||||
if (FetchResponse::hasUidAndSize($oResponse)) {
|
||||
$aReturn[] = new FetchResponse($oResponse);
|
||||
yield new FetchResponse($oResponse);
|
||||
} else if ($this->oLogger) {
|
||||
$this->oLogger->Write('Skipped Imap Response! ['.$oResponse.']', \LOG_NOTICE);
|
||||
}
|
||||
|
|
@ -121,7 +121,14 @@ trait Messages
|
|||
} finally {
|
||||
$this->aFetchCallbacks = array();
|
||||
}
|
||||
}
|
||||
|
||||
public function Fetch(array $aInputFetchItems, string $sIndexRange, bool $bIndexIsUid) : array
|
||||
{
|
||||
$aReturn = array();
|
||||
foreach ($this->FetchIterate($aInputFetchItems, $sIndexRange, $bIndexIsUid) as $oFetchResponse) {
|
||||
$aReturn[] = $oFetchResponse;
|
||||
}
|
||||
return $aReturn;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -479,7 +479,7 @@ class MailClient
|
|||
protected function MessageListByRequestIndexOrUids(MessageCollection $oMessageCollection, SequenceSet $oRange, array &$aAllThreads = []) : void
|
||||
{
|
||||
if (\count($oRange)) {
|
||||
$aFetchResponse = $this->oImapClient->Fetch(array(
|
||||
$aFetchIterator = $this->oImapClient->FetchIterate(array(
|
||||
FetchType::UID,
|
||||
FetchType::RFC822_SIZE,
|
||||
FetchType::INTERNALDATE,
|
||||
|
|
@ -487,31 +487,29 @@ class MailClient
|
|||
FetchType::BODYSTRUCTURE,
|
||||
$this->getEnvelopeOrHeadersRequestString()
|
||||
), (string) $oRange, $oRange->UID);
|
||||
|
||||
if (\count($aFetchResponse)) {
|
||||
$aCollection = \array_fill_keys($oRange->getArrayCopy(), null);
|
||||
foreach ($aFetchResponse as /* @var $oFetchResponseItem \MailSo\Imap\FetchResponse */ $oFetchResponseItem) {
|
||||
$id = $oRange->UID
|
||||
? $oFetchResponseItem->GetFetchValue(FetchType::UID)
|
||||
: $oFetchResponseItem->oImapResponse->ResponseList[1];
|
||||
$oMessage = Message::fromFetchResponse($oMessageCollection->FolderName, $oFetchResponseItem);
|
||||
if ($oMessage) {
|
||||
if ($aAllThreads) {
|
||||
$iUid = $oMessage->Uid;
|
||||
// Find thread and set it.
|
||||
// Used by GUI to delete/move the whole thread or other features
|
||||
foreach ($aAllThreads as $aMap) {
|
||||
if (\in_array($iUid, $aMap)) {
|
||||
$oMessage->SetThreads($aMap);
|
||||
break;
|
||||
}
|
||||
// FETCH does not respond in the id order of the SequenceSet, so we prefill $aCollection for the right sort order.
|
||||
$aCollection = \array_fill_keys($oRange->getArrayCopy(), null);
|
||||
foreach ($aFetchIterator as /* @var $oFetchResponseItem \MailSo\Imap\FetchResponse */ $oFetchResponseItem) {
|
||||
$id = $oRange->UID
|
||||
? $oFetchResponseItem->GetFetchValue(FetchType::UID)
|
||||
: $oFetchResponseItem->oImapResponse->ResponseList[1];
|
||||
$oMessage = Message::fromFetchResponse($oMessageCollection->FolderName, $oFetchResponseItem);
|
||||
if ($oMessage) {
|
||||
if ($aAllThreads) {
|
||||
$iUid = $oMessage->Uid;
|
||||
// Find thread and set it.
|
||||
// Used by GUI to delete/move the whole thread or other features
|
||||
foreach ($aAllThreads as $aMap) {
|
||||
if (\in_array($iUid, $aMap)) {
|
||||
$oMessage->SetThreads($aMap);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$aCollection[$id] = $oMessage;
|
||||
}
|
||||
$aCollection[$id] = $oMessage;
|
||||
}
|
||||
$oMessageCollection->exchangeArray(\array_values(\array_filter($aCollection)));
|
||||
}
|
||||
$oMessageCollection->exchangeArray(\array_values(\array_filter($aCollection)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue