This change should make MessageListByRequestIndexOrUids faster

This commit is contained in:
djmaze 2022-01-06 12:49:00 +01:00
parent 9b25b8580c
commit e3fd72571c
2 changed files with 10 additions and 6 deletions

View file

@ -55,6 +55,11 @@ class SequenceSet /*extends \SplFixedArray*/ implements \Countable
return \array_search($value, $this->data); return \array_search($value, $this->data);
} }
public function getArrayCopy(): array
{
return $this->data;
}
public function __toString(): string public function __toString(): string
{ {
$aResult = array(); $aResult = array();

View file

@ -781,16 +781,15 @@ class MailClient
if (\count($aFetchResponse)) if (\count($aFetchResponse))
{ {
$aCollection = []; $aCollection = \array_fill_keys($oRange->getArrayCopy(), null);
$sFetchType = $oRange->UID ? \MailSo\Imap\Enumerations\FetchType::UID : \MailSo\Imap\Enumerations\FetchType::INDEX; $sFetchType = $oRange->UID ? \MailSo\Imap\Enumerations\FetchType::UID : \MailSo\Imap\Enumerations\FetchType::INDEX;
foreach ($aFetchResponse as /* @var $oFetchResponseItem \MailSo\Imap\FetchResponse */ $oFetchResponseItem) { foreach ($aFetchResponse as /* @var $oFetchResponseItem \MailSo\Imap\FetchResponse */ $oFetchResponseItem) {
$i = $oRange->indexOf($oFetchResponseItem->GetFetchValue($sFetchType)); $id = $oFetchResponseItem->GetFetchValue($sFetchType);
if (false !== $i) { if (\array_key_exists($id, $aCollection)) {
$aCollection[$i] = Message::NewFetchResponseInstance($oMessageCollection->FolderName, $oFetchResponseItem); $aCollection[$id] = Message::NewFetchResponseInstance($oMessageCollection->FolderName, $oFetchResponseItem);
} }
} }
\ksort($aCollection); $oMessageCollection->exchangeArray(\array_values(\array_filter($aCollection)));
$oMessageCollection->exchangeArray(\array_values($aCollection));
} }
} }
} }