mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +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\Net\Exceptions\*
|
||||||
* @throws \MailSo\Imap\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))) {
|
if (!\strlen(\trim($sIndexRange))) {
|
||||||
$this->writeLogException(new \InvalidArgumentException, \LOG_ERR);
|
$this->writeLogException(new \InvalidArgumentException, \LOG_ERR);
|
||||||
|
|
@ -112,7 +112,7 @@ trait Messages
|
||||||
foreach ($this->yieldUntaggedResponses() as $oResponse) {
|
foreach ($this->yieldUntaggedResponses() as $oResponse) {
|
||||||
if (FetchResponse::isValidImapResponse($oResponse)) {
|
if (FetchResponse::isValidImapResponse($oResponse)) {
|
||||||
if (FetchResponse::hasUidAndSize($oResponse)) {
|
if (FetchResponse::hasUidAndSize($oResponse)) {
|
||||||
$aReturn[] = new FetchResponse($oResponse);
|
yield new FetchResponse($oResponse);
|
||||||
} else if ($this->oLogger) {
|
} else if ($this->oLogger) {
|
||||||
$this->oLogger->Write('Skipped Imap Response! ['.$oResponse.']', \LOG_NOTICE);
|
$this->oLogger->Write('Skipped Imap Response! ['.$oResponse.']', \LOG_NOTICE);
|
||||||
}
|
}
|
||||||
|
|
@ -121,7 +121,14 @@ trait Messages
|
||||||
} finally {
|
} finally {
|
||||||
$this->aFetchCallbacks = array();
|
$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;
|
return $aReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -479,7 +479,7 @@ class MailClient
|
||||||
protected function MessageListByRequestIndexOrUids(MessageCollection $oMessageCollection, SequenceSet $oRange, array &$aAllThreads = []) : void
|
protected function MessageListByRequestIndexOrUids(MessageCollection $oMessageCollection, SequenceSet $oRange, array &$aAllThreads = []) : void
|
||||||
{
|
{
|
||||||
if (\count($oRange)) {
|
if (\count($oRange)) {
|
||||||
$aFetchResponse = $this->oImapClient->Fetch(array(
|
$aFetchIterator = $this->oImapClient->FetchIterate(array(
|
||||||
FetchType::UID,
|
FetchType::UID,
|
||||||
FetchType::RFC822_SIZE,
|
FetchType::RFC822_SIZE,
|
||||||
FetchType::INTERNALDATE,
|
FetchType::INTERNALDATE,
|
||||||
|
|
@ -487,31 +487,29 @@ class MailClient
|
||||||
FetchType::BODYSTRUCTURE,
|
FetchType::BODYSTRUCTURE,
|
||||||
$this->getEnvelopeOrHeadersRequestString()
|
$this->getEnvelopeOrHeadersRequestString()
|
||||||
), (string) $oRange, $oRange->UID);
|
), (string) $oRange, $oRange->UID);
|
||||||
|
// FETCH does not respond in the id order of the SequenceSet, so we prefill $aCollection for the right sort order.
|
||||||
if (\count($aFetchResponse)) {
|
$aCollection = \array_fill_keys($oRange->getArrayCopy(), null);
|
||||||
$aCollection = \array_fill_keys($oRange->getArrayCopy(), null);
|
foreach ($aFetchIterator as /* @var $oFetchResponseItem \MailSo\Imap\FetchResponse */ $oFetchResponseItem) {
|
||||||
foreach ($aFetchResponse as /* @var $oFetchResponseItem \MailSo\Imap\FetchResponse */ $oFetchResponseItem) {
|
$id = $oRange->UID
|
||||||
$id = $oRange->UID
|
? $oFetchResponseItem->GetFetchValue(FetchType::UID)
|
||||||
? $oFetchResponseItem->GetFetchValue(FetchType::UID)
|
: $oFetchResponseItem->oImapResponse->ResponseList[1];
|
||||||
: $oFetchResponseItem->oImapResponse->ResponseList[1];
|
$oMessage = Message::fromFetchResponse($oMessageCollection->FolderName, $oFetchResponseItem);
|
||||||
$oMessage = Message::fromFetchResponse($oMessageCollection->FolderName, $oFetchResponseItem);
|
if ($oMessage) {
|
||||||
if ($oMessage) {
|
if ($aAllThreads) {
|
||||||
if ($aAllThreads) {
|
$iUid = $oMessage->Uid;
|
||||||
$iUid = $oMessage->Uid;
|
// Find thread and set it.
|
||||||
// Find thread and set it.
|
// Used by GUI to delete/move the whole thread or other features
|
||||||
// Used by GUI to delete/move the whole thread or other features
|
foreach ($aAllThreads as $aMap) {
|
||||||
foreach ($aAllThreads as $aMap) {
|
if (\in_array($iUid, $aMap)) {
|
||||||
if (\in_array($iUid, $aMap)) {
|
$oMessage->SetThreads($aMap);
|
||||||
$oMessage->SetThreads($aMap);
|
break;
|
||||||
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