mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Cleanup GetUids() cache handling
This commit is contained in:
parent
a400d95444
commit
04bf9cd185
2 changed files with 11 additions and 17 deletions
|
|
@ -129,7 +129,6 @@ abstract class SearchCriterias
|
||||||
|
|
||||||
public static function fromString(\MailSo\Imap\ImapClient $oImapClient, string $sFolderName, string $sSearch, bool $bHideDeleted, bool &$bUseCache = true) : string
|
public static function fromString(\MailSo\Imap\ImapClient $oImapClient, string $sFolderName, string $sSearch, bool $bHideDeleted, bool &$bUseCache = true) : string
|
||||||
{
|
{
|
||||||
$bUseCache = true;
|
|
||||||
$iTimeFilter = 0;
|
$iTimeFilter = 0;
|
||||||
$aCriteriasResult = array();
|
$aCriteriasResult = array();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -748,7 +748,7 @@ class MailClient
|
||||||
|
|
||||||
$aResultUids = false;
|
$aResultUids = false;
|
||||||
$bUidsFromCacher = false;
|
$bUidsFromCacher = false;
|
||||||
$bUseCacheAfterSearch = true;
|
$bUseCacheAfterSearch = $oCacher && $oCacher->IsInited();
|
||||||
|
|
||||||
$sSerializedHash = '';
|
$sSerializedHash = '';
|
||||||
$sSerializedLog = '';
|
$sSerializedLog = '';
|
||||||
|
|
@ -756,25 +756,23 @@ class MailClient
|
||||||
$bUseSortIfSupported = $bUseSortIfSupported && !\strlen($sSearch) && $this->oImapClient->IsSupported('SORT');
|
$bUseSortIfSupported = $bUseSortIfSupported && !\strlen($sSearch) && $this->oImapClient->IsSupported('SORT');
|
||||||
|
|
||||||
$sSearchCriterias = \MailSo\Imap\SearchCriterias::fromString($this->oImapClient, $sFolderName, $sSearch, $oParams->bHideDeleted, $bUseCacheAfterSearch);
|
$sSearchCriterias = \MailSo\Imap\SearchCriterias::fromString($this->oImapClient, $sFolderName, $sSearch, $oParams->bHideDeleted, $bUseCacheAfterSearch);
|
||||||
if ($bUseCacheAfterSearch && $oCacher && $oCacher->IsInited())
|
// Disabled for now as there are many cases that change the result
|
||||||
{
|
$bUseCacheAfterSearch = false;
|
||||||
|
if ($bUseCacheAfterSearch) {
|
||||||
$sSerializedHash = 'GetUids/'.
|
$sSerializedHash = 'GetUids/'.
|
||||||
($bUseSortIfSupported ? 'S' . $sSort : 'N').'/'.
|
($bUseSortIfSupported ? 'S' . $sSort : 'N').'/'.
|
||||||
$this->GenerateImapClientHash().'/'.
|
$this->GenerateImapClientHash().'/'.
|
||||||
$sFolderName.'/'.$sSearchCriterias;
|
$sFolderName.'/'.$sSearchCriterias;
|
||||||
$sSerializedLog = '"'.$sFolderName.'" / '.$sSearchCriterias.'';
|
$sSerializedLog = '"'.$sFolderName.'" / '.$sSearchCriterias.'';
|
||||||
|
|
||||||
// $sSerialized = $oCacher->Get($sSerializedHash);
|
$sSerialized = $oCacher->Get($sSerializedHash);
|
||||||
if (!empty($sSerialized))
|
if (!empty($sSerialized)) {
|
||||||
{
|
|
||||||
$aSerialized = \json_decode($sSerialized, true);
|
$aSerialized = \json_decode($sSerialized, true);
|
||||||
if (\is_array($aSerialized) && isset($aSerialized['FolderHash'], $aSerialized['Uids']) &&
|
if (\is_array($aSerialized) && isset($aSerialized['FolderHash'], $aSerialized['Uids']) &&
|
||||||
$sFolderHash === $aSerialized['FolderHash'] &&
|
$sFolderHash === $aSerialized['FolderHash'] &&
|
||||||
\is_array($aSerialized['Uids'])
|
\is_array($aSerialized['Uids'])
|
||||||
)
|
) {
|
||||||
{
|
if ($this->oLogger) {
|
||||||
if ($this->oLogger)
|
|
||||||
{
|
|
||||||
$this->oLogger->Write('Get Serialized UIDS from cache ('.$sSerializedLog.') [count:'.\count($aSerialized['Uids']).']');
|
$this->oLogger->Write('Get Serialized UIDS from cache ('.$sSerializedLog.') [count:'.\count($aSerialized['Uids']).']');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -784,8 +782,7 @@ class MailClient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!\is_array($aResultUids))
|
if (!$bUidsFromCacher) {
|
||||||
{
|
|
||||||
if ($bUseSortIfSupported) {
|
if ($bUseSortIfSupported) {
|
||||||
// $this->oImapClient->IsSupported('ESORT')
|
// $this->oImapClient->IsSupported('ESORT')
|
||||||
// $aResultUids = $this->oImapClient->MessageSimpleESort(array($sSort ?: 'REVERSE DATE'), $sSearchCriterias)['ALL'];
|
// $aResultUids = $this->oImapClient->MessageSimpleESort(array($sSort ?: 'REVERSE DATE'), $sSearchCriterias)['ALL'];
|
||||||
|
|
@ -796,15 +793,13 @@ class MailClient
|
||||||
$aResultUids = $this->oImapClient->MessageSimpleSearch($sSearchCriterias, true, \MailSo\Base\Utils::IsAscii($sSearchCriterias) ? '' : 'UTF-8');
|
$aResultUids = $this->oImapClient->MessageSimpleSearch($sSearchCriterias, true, \MailSo\Base\Utils::IsAscii($sSearchCriterias) ? '' : 'UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$bUidsFromCacher && $bUseCacheAfterSearch && \is_array($aResultUids) && $oCacher && $oCacher->IsInited() && \strlen($sSerializedHash))
|
if ($bUseCacheAfterSearch) {
|
||||||
{
|
|
||||||
$oCacher->Set($sSerializedHash, \json_encode(array(
|
$oCacher->Set($sSerializedHash, \json_encode(array(
|
||||||
'FolderHash' => $sFolderHash,
|
'FolderHash' => $sFolderHash,
|
||||||
'Uids' => $aResultUids
|
'Uids' => $aResultUids
|
||||||
)));
|
)));
|
||||||
|
|
||||||
if ($this->oLogger)
|
if ($this->oLogger) {
|
||||||
{
|
|
||||||
$this->oLogger->Write('Save Serialized UIDS to cache ('.$sSerializedLog.') [count:'.\count($aResultUids).']');
|
$this->oLogger->Write('Save Serialized UIDS to cache ('.$sSerializedLog.') [count:'.\count($aResultUids).']');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue