Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Fixed: more strong optimazation for [labs]imap_message_list_count_lim…
Browse files Browse the repository at this point in the history
…it_trigger (#903)
  • Loading branch information
RainLoop committed Nov 27, 2015
1 parent d844938 commit d890a6d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
5 changes: 5 additions & 0 deletions rainloop/v/0.0.0/app/libraries/MailSo/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class Config
*/
public static $MessageListCountLimitTrigger = 0;

/**
* @var bool
*/
public static $MessageListUndeletedOnly = true;

/**
* @var int
*/
Expand Down
55 changes: 50 additions & 5 deletions rainloop/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,10 @@ private function getImapSearchCriterias($sSearch, $sFilter, $iTimeZoneOffset = 0
}

$sCriteriasResult = \trim($sCriteriasResult);
$sCriteriasResult .= ' UNDELETED';
if (\MailSo\Config::$MessageListUndeletedOnly)
{
$sCriteriasResult = \trim($sCriteriasResult.' UNDELETED');
}

$sFilter = \trim($sFilter);
if ('' !== $sFilter)
Expand All @@ -1423,7 +1426,7 @@ private function getImapSearchCriterias($sSearch, $sFilter, $iTimeZoneOffset = 0
$sCriteriasResult = \trim($sCriteriasResult);
if ('' !== \MailSo\Config::$MessageListPermanentFilter)
{
$sCriteriasResult .= ' '.\MailSo\Config::$MessageListPermanentFilter;
$sCriteriasResult = \trim($sCriteriasResult.' '.\MailSo\Config::$MessageListPermanentFilter);
}

$sCriteriasResult = \trim($sCriteriasResult);
Expand Down Expand Up @@ -1865,7 +1868,7 @@ public function GetUids($oCacher, $sSearch, $sFilter, $sFolderName, $sFolderHash
}
}

return $aResultUids;
return \is_array($aResultUids) ? $aResultUids : array();
}

/**
Expand Down Expand Up @@ -1964,7 +1967,7 @@ public function MessageList($sFolderName, $iOffset = 0, $iLimit = 10, $sSearch =
$bUseThreadSortIfSupported = false;
}

if (0 < $iMessageRealCount)
if (0 < $iMessageRealCount && !$bMessageListOptimization)
{
$mAllSortedUids = $this->GetUids($oCacher, '', $sFilter,
$oMessageCollection->FolderName, $oMessageCollection->FolderHash, $bUseSortIfSupported);
Expand Down Expand Up @@ -2061,11 +2064,53 @@ public function MessageList($sFolderName, $iOffset = 0, $iLimit = 10, $sSearch =

if (0 < \count($aUids))
{
$iOffset = (0 > $iOffset) ? 0 : $iOffset;
$aRequestUids = \array_slice($aUids, $iOffset, $iLimit);
$this->MessageListByRequestIndexOrUids($oMessageCollection, $aRequestUids, true);
}
}
}
else if (0 < $iMessageRealCount)
{
if ($this->oLogger)
{
$this->oLogger->Write('List optimization (count: '.$iMessageRealCount.
', limit:'.\MailSo\Config::$MessageListCountLimitTrigger.')');
}

$oMessageCollection->MessageCount = $iMessageRealCount;
$oMessageCollection->MessageUnseenCount = $iMessageUnseenCount;

if (0 < \strlen($sSearch) || $bUseFilter)
{
$aUids = $this->GetUids($oCacher, $sSearch, $sFilter,
$oMessageCollection->FolderName, $oMessageCollection->FolderHash);

if (0 < \count($aUids))
{
$oMessageCollection->MessageResultCount = \count($aUids);

$aRequestUids = \array_slice($aUids, $iOffset, $iLimit);
$this->MessageListByRequestIndexOrUids($oMessageCollection, $aRequestUids, true);
}
else
{
$oMessageCollection->MessageResultCount = 0;
}
}
else
{
$oMessageCollection->MessageResultCount = $iMessageRealCount;

if (1 < $iMessageRealCount)
{
$aRequestIndexes = \array_slice(array_reverse(range(1, $iMessageRealCount)), $iOffset, $iLimit);
}
else
{
$aRequestIndexes = \array_slice(array(1), $iOffset, $iLimit);
}

$this->MessageListByRequestIndexOrUids($oMessageCollection, $aRequestIndexes, false);
}
}

Expand Down

0 comments on commit d890a6d

Please sign in to comment.