Optimizations

Added "[labs]imap_folder_list_limit" setting (optimization)
This commit is contained in:
RainLoop Team 2015-01-08 02:50:59 +04:00
parent 833f40c115
commit 7ef9ebb45f
22 changed files with 878 additions and 32 deletions

View file

@ -608,7 +608,8 @@ class ImapClient extends \MailSo\Net\NetClient
/**
* @param array $aResult
* @param bool $bIsSubscribeList
* @param string $sStatus
* @param bool $bUseListStatus = false
*
* @return array
*/

View file

@ -196,6 +196,14 @@ class Attachment
return $this->oBodyStructure ? $this->oBodyStructure->IsDoc() : false;
}
/**
* @return bool
*/
public function IsPgpSignature()
{
return $this->oBodyStructure ? $this->oBodyStructure->IsPgpSignature() : false;
}
/**
* @return \MailSo\Mail\Attachment
*/

View file

@ -104,4 +104,16 @@ class AttachmentCollection extends \MailSo\Base\Collection
return \is_array($aList) ? \count($aList) : 0;
}
/**
* @return int
*/
public function CertificateCount()
{
$aList = $this->FilterList(function ($oAttachment) {
return $oAttachment && $oAttachment->IsPgpSignature();
});
return \is_array($aList) ? \count($aList) : 0;
}
}

View file

@ -32,6 +32,11 @@ class FolderCollection extends \MailSo\Base\Collection
*/
public $IsThreadsSupported;
/**
* @var bool
*/
public $Optimized;
/**
* @var array
*/
@ -48,6 +53,7 @@ class FolderCollection extends \MailSo\Base\Collection
$this->FoldersHash = '';
$this->SystemFolders = array();
$this->IsThreadsSupported = false;
$this->Optimized = false;
}
/**

View file

@ -1914,7 +1914,8 @@ class MailClient
if (1 < $iMessageCount)
{
if ($bMessageListOptimization || 0 === \MailSo\Config::$MessageListDateFilter)
if (0 === \MailSo\Config::$MessageListDateFilter &&
($bMessageListOptimization || !$bUseSortIfSupported))
{
$aIndexOrUids = \array_reverse(\range(1, $iMessageCount));
}
@ -2013,19 +2014,140 @@ class MailClient
return \is_array($aUids) && 1 === \count($aUids) && \is_numeric($aUids[0]) ? (int) $aUids[0] : null;
}
/**
* @param array $aMailFoldersHelper
* @param int $iOptimizationLimit = 0
*
* @return array
*/
public function folerListOptimization($aMailFoldersHelper, $iOptimizationLimit = 0)
{
// optimization
if (10 < $iOptimizationLimit && $iOptimizationLimit < \count($aMailFoldersHelper))
{
if ($this->oLogger)
{
$this->oLogger->Write('Start optimization (limit:'.$iOptimizationLimit.') for '.\count($aMailFoldersHelper).' folders');
}
$iForeachLimit = 1;
$aFilteredNames = array(
'inbox',
'sent', 'outbox', 'sentmail',
'drafts',
'junk', 'spam',
'trash', 'bin',
'archive', 'allmail', 'all',
'starred', 'flagged', 'important'
);
$aNewMailFoldersHelper = array();
$iCountLimit = $iForeachLimit;
foreach ($aMailFoldersHelper as $iIndex => /* @var $oImapFolder \MailSo\Mail\Folder */ $oFolder)
{
// normal and subscribed only
if ($oFolder && ($oFolder->IsSubscribed() || \in_array(\strtolower($oFolder->NameRaw()), $aFilteredNames)))
{
$aNewMailFoldersHelper[] = $oFolder;
$aMailFoldersHelper[$iIndex] = null;
$iCountLimit--;
}
if (0 > $iCountLimit)
{
if ($iOptimizationLimit < \count($aNewMailFoldersHelper))
{
break;
}
else
{
$iCountLimit = $iForeachLimit;
}
}
}
$iCountLimit = $iForeachLimit;
if ($iOptimizationLimit >= \count($aNewMailFoldersHelper))
{
// name filter
foreach ($aMailFoldersHelper as $iIndex => /* @var $oImapFolder \MailSo\Mail\Folder */ $oFolder)
{
if ($oFolder && !\preg_match('/[{}\[\]]/', $oFolder->NameRaw()))
{
$aNewMailFoldersHelper[] = $oFolder;
$aMailFoldersHelper[$iIndex] = null;
$iCountLimit--;
}
if (0 > $iCountLimit)
{
if ($iOptimizationLimit < \count($aNewMailFoldersHelper))
{
break;
}
else
{
$iCountLimit = $iForeachLimit;
}
}
}
}
$iCountLimit = $iForeachLimit;
if ($iOptimizationLimit >= \count($aNewMailFoldersHelper))
{
// other
foreach ($aMailFoldersHelper as $iIndex => /* @var $oImapFolder \MailSo\Mail\Folder */ $oFolder)
{
if ($oFolder)
{
$aNewMailFoldersHelper[] = $oFolder;
$aMailFoldersHelper[$iIndex] = null;
$iCountLimit--;
}
if (0 > $iCountLimit)
{
if ($iOptimizationLimit < \count($aNewMailFoldersHelper))
{
break;
}
else
{
$iCountLimit = $iForeachLimit;
}
}
}
}
$aMailFoldersHelper = $aNewMailFoldersHelper;
if ($this->oLogger)
{
$this->oLogger->Write('Result optimization: '.\count($aMailFoldersHelper).' folders');
}
}
return $aMailFoldersHelper;
}
/**
* @param string $sParent = ''
* @param string $sListPattern = '*'
* @param bool $bUseListSubscribeStatus = false
* @param int $iOptimizationLimit = 0
*
* @return \MailSo\Mail\FolderCollection|false
*/
public function Folders($sParent = '', $sListPattern = '*', $bUseListSubscribeStatus = true)
public function Folders($sParent = '', $sListPattern = '*', $bUseListSubscribeStatus = true, $iOptimizationLimit = 0)
{
$oFolderCollection = false;
$aFolders = $this->oImapClient->FolderList($sParent, $sListPattern);
$aSubscribedFolders = null;
if ($bUseListSubscribeStatus)
{
@ -2046,7 +2168,11 @@ class MailClient
}
}
$aFolders = $this->oImapClient->FolderList($sParent, $sListPattern);
$bOptimized = false;
$aMailFoldersHelper = null;
if (\is_array($aFolders))
{
$aMailFoldersHelper = array();
@ -2058,12 +2184,19 @@ class MailClient
$oImapFolder->IsInbox()
);
}
$iCount = \count($aMailFoldersHelper);
$aMailFoldersHelper = $this->folerListOptimization($aMailFoldersHelper, $iOptimizationLimit);
$bOptimized = $iCount !== \count($aMailFoldersHelper);
}
if (\is_array($aMailFoldersHelper))
{
$oFolderCollection = FolderCollection::NewInstance();
$oFolderCollection->InitByUnsortedMailFolderArray($aMailFoldersHelper);
$oFolderCollection->Optimized = $bOptimized;
}
if ($oFolderCollection)