abandon folderStatusCache and rely completely on hordes cache capability and handling

This commit is contained in:
Klaus Leithoff 2013-11-19 11:17:32 +00:00
parent 74d0797904
commit e5818d9b62
2 changed files with 67 additions and 121 deletions

View File

@ -30,7 +30,7 @@ class mail_bo
* @var string
*/
static $displayCharset;
static $activeFolderCache;
static $folderStatusCache;
/**
@ -353,8 +353,9 @@ $_restoreSession=false;
*/
function restoreSessionData()
{
$this->sessionData = egw_cache::getCache(egw_cache::SESSION,'mail','session_data',$callback=null,$callback_params=array(),$expiration=60*60*1);
self::$folderStatusCache = egw_cache::getCache(egw_cache::INSTANCE,'email','folderStatus'.trim($GLOBALS['egw_info']['user']['account_id']),$callback=null,$callback_params=array(),$expiration=60*60*10);
$this->sessionData = array();//egw_cache::getCache(egw_cache::SESSION,'mail','session_data',$callback=null,$callback_params=array(),$expiration=60*60*1);
self::$activeFolderCache = egw_cache::getCache(egw_cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),$callback=null,$callback_params=array(),$expiration=60*60*10);
if (!empty(self::$activeFolderCache[$this->profileID])) $this->sessionData['mailbox'] = self::$activeFolderCache[$this->profileID];
}
/**
@ -362,11 +363,13 @@ $_restoreSession=false;
*/
function saveSessionData()
{
if (isset(self::$folderStatusCache) && is_array(self::$folderStatusCache))
//error_log(__METHOD__.__LINE__.array2string(array_keys($this->sessionData)));
if (!empty($this->sessionData['mailbox'])) self::$activeFolderCache[$this->profileID]=$this->sessionData['mailbox'];
if (isset(self::$activeFolderCache) && is_array(self::$activeFolderCache))
{
egw_cache::setCache(egw_cache::INSTANCE,'email','folderStatus'.trim($GLOBALS['egw_info']['user']['account_id']),self::$folderStatusCache, $expiration=60*60*10);
egw_cache::setCache(egw_cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),$this->sessionData['maibox'], $expiration=60*60*10);
}
egw_cache::setCache(egw_cache::SESSION,'mail','session_data',$this->sessionData, $expiration=60*60*1);
//egw_cache::setCache(egw_cache::SESSION,'mail','session_data',$this->sessionData, $expiration=60*60*1);
}
/**
@ -455,18 +458,12 @@ $_restoreSession=false;
unset($_specialUseFolders[$_ImapServerId]);
self::$specialUseFolders=null;
}
self::$folderStatusCache = egw_cache::getCache(egw_cache::INSTANCE,'email','folderStatus'.trim($GLOBALS['egw_info']['user']['account_id']),$callback=null,$callback_params=array(),$expiration=60*60*10);
if (isset(self::$folderStatusCache[$_ImapServerId]))
{
self::$folderStatusCache[$_ImapServerId]=null;
}
}
egw_cache::setCache(egw_cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),$folders2return, $expiration=60*60*1);
egw_cache::setCache(egw_cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderInfo,$expiration=60*5);
egw_cache::setCache(egw_cache::INSTANCE,'email','lastFolderUsedForMove'.trim($GLOBALS['egw_info']['user']['account_id']),$lastFolderUsedForMove,$expiration=60*60*1);
egw_cache::setCache(egw_cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderBasicInfo,$expiration=60*60*1);
egw_cache::setCache(egw_cache::INSTANCE,'email','specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']),$_specialUseFolders,$expiration=60*60*12);
egw_cache::setCache(egw_cache::INSTANCE,'email','folderStatus'.trim($GLOBALS['egw_info']['user']['account_id']),self::$folderStatusCache,$expiration=60*60*10);
}
/**
@ -859,11 +856,12 @@ $_restoreSession=false;
if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly) return $folderInfoCache[$_folderName];
$retValue = array();
$retValue['subscribed'] = false;
/*
if(!$icServer = emailadmin_account::read($this->profileID)) {
if (self::$debug) error_log(__METHOD__." no Server found for Folder:".$_folderName);
return false;
}
*/
// does the folder exist???
if (is_null($folderInfoCache) || !isset($folderInfoCache[$_folderName])) $folderInfoCache[$_folderName] = $this->icServer->getMailboxes('', $_folderName, true);
$folderInfo = $folderInfoCache[$_folderName];
@ -1259,16 +1257,7 @@ $_restoreSession=false;
*/
function getSortedList($_folderName, $_sort, &$_reverse, $_filter, &$resultByUid=true, $setSession=true)
{
//ToDo: FilterSpecific Cache
if (is_null(self::$folderStatusCache) || empty(self::$folderStatusCache[$this->profileID]) || empty(self::$folderStatusCache[$this->profileID][$_folderName]))
{
self::$folderStatusCache = egw_cache::getCache(egw_cache::INSTANCE,'email','folderStatus'.trim($GLOBALS['egw_info']['user']['account_id']),$callback=null,$callback_params=array(),$expiration=60*60*10);
}
if($folderStatus = $this->icServer->examineMailbox($_folderName)) {
//if (stripos($folderStatus->message,'not connected') !== false); error_log(__METHOD__.__LINE__.$folderStatus->message);
//return false;
}
$folderStatus = $this->icServer->examineMailbox($_folderName);
//error_log(__METHOD__.__LINE__.' F:'.$_folderName.' S:'.array2string($folderStatus));
//error_log(__METHOD__.__LINE__.' Filter:'.array2string($_filter));
$try2useCache = true;
@ -1289,40 +1278,7 @@ $_restoreSession=false;
//error_log(__METHOD__.__LINE__.' Profile:'.$this->profileID.' Folder:'.$_folderName.' -> EXISTS/SessStat:'.array2string($folderStatus['MESSAGES']).'/'.self::$folderStatusCache[$this->profileID][$_folderName]['messages'].' ListContDelMsg/SessDeleted:'.$eMailListContainsDeletedMessages[$this->profileID][$_folderName].'/'.self::$folderStatusCache[$this->profileID][$_folderName]['deleted']);
//error_log(__METHOD__.__LINE__.' Took:'.$r.'(s) setting eMailListContainsDeletedMessages for Profile:'.$this->profileID.' Folder:'.$_folderName.' to '.$eMailListContainsDeletedMessages[$this->profileID][$_folderName]);
}
if (self::$debug)
{
error_log(__METHOD__.__LINE__.' Profile:'.$this->profileID.' Folder:'.$_folderName.' -> EXISTS/SessStat:'.array2string($folderStatus['MESSAGES']).'/'.self::$folderStatusCache[$this->profileID][$_folderName]['messages'].' ListContDelMsg/SessDeleted:'.$eMailListContainsDeletedMessages[$this->profileID][$_folderName].'/'.self::$folderStatusCache[$this->profileID][$_folderName]['deleted']);
error_log(__METHOD__.__LINE__.' FolderStatus:'.' Folder:'.$_folderName.' :'.array2string($folderStatus));
error_log(__METHOD__.__LINE__.' CachedFolderStatus:'.array2string(self::$folderStatusCache[$this->profileID][$_folderName]));
}
if($try2useCache && (is_array(self::$folderStatusCache[$this->profileID][$_folderName]) &&
self::$folderStatusCache[$this->profileID][$_folderName]['uidValidity'] === $folderStatus['UIDVALIDITY'] &&
self::$folderStatusCache[$this->profileID][$_folderName]['messages'] == $folderStatus['MESSAGES'] &&
self::$folderStatusCache[$this->profileID][$_folderName]['deleted'] == $eMailListContainsDeletedMessages[$this->profileID][$_folderName] &&
self::$folderStatusCache[$this->profileID][$_folderName]['uidnext'] === $folderStatus['UIDNEXT'] &&
self::$folderStatusCache[$this->profileID][$_folderName]['filter'] === $_filter &&
self::$folderStatusCache[$this->profileID][$_folderName]['sort'] === $_sort &&
//self::$folderStatusCache[0][$_folderName]['reverse'] === $_reverse &&
!empty(self::$folderStatusCache[$this->profileID][$_folderName]['sortResult']))
) {
if (self::$debug) error_log(__METHOD__." USE CACHE for Profile:". $this->profileID." Folder:".$_folderName.'->'.($setSession?'setSession':'checkrun').' Filter:'.array2string($_filter).function_backtrace());
$sortResult = self::$folderStatusCache[$this->profileID][$_folderName]['sortResult'];
} else {
$try2useCache = false;
// control HeaderCache
if (isset(self::$folderStatusCache[$this->profileID][$_folderName]['uidValidity']) &&
self::$folderStatusCache[$this->profileID][$_folderName]['uidValidity'] != $folderStatus['UIDVALIDITY'])
{
$summary = egw_cache::getCache(egw_cache::INSTANCE,'email','summaryCache'.trim($GLOBALS['egw_info']['user']['account_id']),$callback=null,$callback_params=array(),$expiration=60*60*1);
if (isset($summary[$this->profileID][$_folderName]))
{
unset($summary[$this->profileID][$_folderName]);
egw_cache::setCache(egw_cache::INSTANCE,'email','summaryCache'.trim($GLOBALS['egw_info']['user']['account_id']),$summary, $expiration=60*60*1);
}
}
//error_log(__METHOD__." USE NO CACHE for Profile:". $this->profileID." Folder:".$_folderName.'->'.($setSession?'setSession':'checkrun'));
if (self::$debug) error_log(__METHOD__." USE NO CACHE for Profile:". $this->profileID." Folder:".$_folderName." Filter:".array2string($_filter).function_backtrace());
$filter = $this->createIMAPFilter($_folderName, $_filter);
//_debug_array($filter);
@ -1368,19 +1324,6 @@ $_restoreSession=false;
self::$folderStatusCache[$this->profileID][$_folderName]['sortResult'] = $sortResult;
self::$folderStatusCache[$this->profileID][$_folderName]['sort'] = $_sort;
}
}
if ($setSession)
{
/*
// this indicates, that there should be no UNDELETED Messages in the returned set/subset
if (((strpos(array2string($_filter), 'UNDELETED') === false && strpos(array2string($_filter), 'DELETED') === false)))
{
if ($try2useCache == false) self::$folderStatusCache[$this->profileID][$_folderName]['deleted'] = $eMailListContainsDeletedMessages[$this->profileID][$_folderName];
}
*/
self::$folderStatusCache[$this->profileID][$_folderName]['reverse'] = $_reverse;
egw_cache::setCache(egw_cache::INSTANCE,'email','folderStatus'.trim($GLOBALS['egw_info']['user']['account_id']),self::$folderStatusCache,$expiration=60*60*10);
}
//_debug_array($sortResult['match']->ids);
return $sortResult;
}
@ -2713,10 +2656,6 @@ $_restoreSession=false;
function flagMessages($_flag, $_messageUID,$_folder=NULL)
{
//error_log(__METHOD__.__LINE__.'->' .$_flag." ".array2string($_messageUID).",$_folder /".$this->sessionData['mailbox']);
if (is_null(self::$folderStatusCache) || empty(self::$folderStatusCache[$this->profileID]) || empty(self::$folderStatusCache[$this->profileID][$_folderName]))
{
self::$folderStatusCache = egw_cache::getCache(egw_cache::INSTANCE,'email','folderStatus'.trim($GLOBALS['egw_info']['user']['account_id']),$callback=null,$callback_params=array(),$expiration=60*60*10);
}
if(!is_array($_messageUID)) {
#return false;
if ($_messageUID=='all')
@ -2827,7 +2766,6 @@ $_restoreSession=false;
}
self::$folderStatusCache[$this->profileID][(!empty($_folder)?$_folder: $this->sessionData['mailbox'])]['uidValidity'] = 0;
egw_cache::setCache(egw_cache::INSTANCE,'email','folderStatus'.trim($GLOBALS['egw_info']['user']['account_id']),self::$folderStatusCache,$expiration=60*60*10);
//error_log(__METHOD__.__LINE__.'->' .$_flag." ".array2string($_messageUID).",".($_folder?$_folder:$this->sessionData['mailbox']));
return true; // as we do not catch/examine setFlags returnValue

View File

@ -99,6 +99,7 @@ class mail_ui
*/
function __construct()
{
//$starttime = microtime (true);
if (!isset($GLOBALS['egw_info']['flags']['js_link_registry']))
{
//error_log(__METHOD__.__LINE__.' js_link_registry not set, force it:'.array2string($GLOBALS['egw_info']['flags']['js_link_registry']));
@ -143,6 +144,8 @@ class mail_ui
}
$GLOBALS['egw']->session->commit_session();
//_debug_array($this->mail_bo->mailPreferences);
//$endtime = microtime(true) - $starttime;
//error_log(__METHOD__.__LINE__. " time used: ".$endtime);
}
/**
@ -180,8 +183,9 @@ class mail_ui
*/
function index(array $content=null,$msg=null)
{
//$starttime = microtime (true);
$this->mail_bo->restoreSessionData();
$sessionFolder = $this->mail_bo->sessionData['maibox'];
$sessionFolder = $this->mail_bo->sessionData['mailbox'];
if ($this->mail_bo->folderExists($sessionFolder))
{
$this->mail_bo->reopen($sessionFolder); // needed to fetch full set of capabilities
@ -259,12 +263,12 @@ class mail_ui
$sel_options[self::$nm_index]['foldertree'] = $this->getFolderTree(false);
//$sessionFolder = $this->mail_bo->sessionData['maibox'];// already set and tested this earlier
if ($this->mail_bo->folderExists($sessionFolder))
{
$content[self::$nm_index]['selectedFolder'] = $this->mail_bo->profileID.self::$delimiter.$this->mail_bo->sessionData['maibox'];
//$sessionFolder = $this->mail_bo->sessionData['mailbox'];// already set and tested this earlier
//if ($this->mail_bo->folderExists($sessionFolder))
//{
$content[self::$nm_index]['selectedFolder'] = $this->mail_bo->profileID.self::$delimiter.(!empty($this->mail_bo->sessionData['mailbox'])?$this->mail_bo->sessionData['mailbox']:'INBOX');
//$this->mail_bo->reopen($sessionFolder); // needed to fetch full set of capabilities: but did that earlier
}
//}
// since we are connected,(and selected the folder) we check for capabilities SUPPORTS_KEYWORDS to eventually add the keyword filters
if ( $this->mail_bo->icServer->hasCapability('SUPPORTS_KEYWORDS'))
{
@ -345,6 +349,9 @@ class mail_ui
if (empty($content[self::$nm_index]['filter2']) || empty($content[self::$nm_index]['search'])) $content[self::$nm_index]['filter2']='quick';
$readonlys = $preserv = $sel_options;
//$endtime = microtime(true) - $starttime;
//error_log(__METHOD__.__LINE__. " time used: ".$endtime);
return $etpl->exec('mail.mail_ui.index',$content,$sel_options,$readonlys,$preserv);
}
@ -1089,11 +1096,11 @@ unset($query['actions']);
$this->mail_bo->restoreSessionData();
$maxMessages = 50; // match the hardcoded setting for data retrieval as inital value
$previewMessage = $this->mail_bo->sessionData['previewMessage'];
if (isset($query['selectedFolder'])) $this->mail_bo->sessionData['maibox']=$query['selectedFolder'];
if (isset($query['selectedFolder'])) $this->mail_bo->sessionData['mailbox']=$query['selectedFolder'];
$this->mail_bo->saveSessionData();
$sRToFetch = null;
$_folderName=$query['selectedFolder'];
$_folderName=(!empty($query['selectedFolder'])?$query['selectedFolder']:$this->mail_bo->profileID.self::$delimiter.'INBOX');
list($_profileID,$folderName) = explode(self::$delimiter,$_folderName,2);
if (is_numeric($_profileID))
{
@ -1102,10 +1109,10 @@ unset($query['actions']);
//error_log(__METHOD__.__LINE__.' change Profile to ->'.$_profileID);
$this->changeProfile($_profileID);
}
$_folderName = $folderName;
$_folderName = (!empty($folderName)?$folderName:'INBOX');
}
//save selected Folder to sessionData (mailbox)->currentFolder
if (isset($query['selectedFolder'])) $this->mail_bo->sessionData['maibox']=$_folderName;
if (isset($query['selectedFolder'])) $this->mail_bo->sessionData['mailbox']=$_folderName;
$this->mail_bo->saveSessionData();
$rowsFetched['messages'] = null;
@ -1201,8 +1208,9 @@ unset($query['actions']);
if ($GLOBALS['egw_info']['user']['preferences']['common']['select_mode']=='EGW_SELECTMODE_TOGGLE') unset($cols[0]);
$rows = $this->header2gridelements($sortResult['header'],$cols, $_folderName, $folderType,$previewMessage);
//error_log(__METHOD__.__LINE__.array2string($rows));
$endtime = microtime(true) - $starttime;
//error_log(__METHOD__.__LINE__.' SelectedFolder:'.$query['selectedFolder'].' Start:'.$query['start'].' NumRows:'.$query['num_rows'].' Took:'.$endtime);
//$endtime = microtime(true) - $starttime;
//error_log(__METHOD__.__LINE__. " time used: ".$endtime.' for Folder:'.$_folderName);
return $rowsFetched['messages'];
}
@ -3375,7 +3383,7 @@ blockquote[type=cite] {
function ajax_compressFolder()
{
$this->mail_bo->restoreSessionData();
$folder = $this->mail_bo->sessionData['maibox'];
$folder = $this->mail_bo->sessionData['mailbox'];
if ($this->mail_bo->folderExists($folder))
{
if(!empty($folder)) {