Avoid to call mail constructor (openConnection is an expensive operation) when client-side ask for vacationNotice.

-Check if there's no vacation cached then create mail object (try openConnection) and ask for vacation
-Add account_lid to cached vacations to distinguished them in case if the mail account was a shared profile
This commit is contained in:
Hadi Nategh 2014-08-11 12:14:27 +00:00
parent f22b156f21
commit cb093e7266
2 changed files with 29 additions and 23 deletions

View File

@ -621,7 +621,10 @@ class mail_sieve
self::setAsyncJob($newVacation);
}
//Reset vacationNotice cache which is used in mail_ui get_rows
egw_cache::unsetCache(egw_cache::INSTANCE,'email', 'vacationNotice'+$icServer->acc_id);
$cachedVacations = egw_cache::getCache(egw_cache::INSTANCE, 'email', 'vacationNotice'+$GLOBALS['egw_info']['user']['account_lid']);
$cachedVacations = array($icServer->acc_id => $newVacation) + (array)$cachedVacations;
egw_cache::setCache(egw_cache::INSTANCE,'email', 'vacationNotice'+$GLOBALS['egw_info']['user']['account_lid'], $cachedVacations);
$msg = lang('Vacation notice sucessfully updated.');
}
}

View File

@ -2284,32 +2284,25 @@ class mail_ui
/**
* fetch vacation info from active Server using icServer object
*
* @param array $cachedVacations an array of cached vacations for an user
* @return array|boolean array with vacation on success or false on failure
*/
function gatherVacation()
function gatherVacation($cachedVacations = array())
{
$vacation = $this->mail_bo->icServer->acc_sieve_enabled && ($this->mail_bo->icServer->acc_sieve_host||$this->mail_bo->icServer->acc_imap_host);
$isVacationEnabled = $this->mail_bo->icServer->acc_sieve_enabled && ($this->mail_bo->icServer->acc_sieve_host||$this->mail_bo->icServer->acc_imap_host);
//error_log(__METHOD__.__LINE__.' Server:'.self::$icServerID.' Sieve Enabled:'.array2string($vacation));
if ($vacation)
if ($isVacationEnabled)
{
$sieveServer = $this->mail_bo->icServer;
try
{
//Get vacation from cache if it's available
$vacationCached = egw_cache::getCache(egw_cache::INSTANCE, 'email', 'vacationNotice'+$sieveServer->acc_id);
$sieveServer->retrieveRules();
$vacation = $sieveServer->getVacation();
if (!$vacationCached)
{
$sieveServer->retrieveRules();
$vacation = $sieveServer->getVacation();
// Set vacation to the instance cache for particular account
egw_cache::setCache(egw_cache::INSTANCE, 'email', 'vacationNotice'+$sieveServer->acc_id, $vacation);
}
else
{
return $vacationCached;
}
$cachedVacations = array($sieveServer->acc_id => $vacation) + $cachedVacations;
// Set vacation to the instance cache for particular account with expiration of one day
egw_cache::setCache(egw_cache::INSTANCE, 'email', 'vacationNotice'+$GLOBALS['egw_info']['user']['account_lid'], $cachedVacations, 60*60*24);
} catch (PEAR_Exception $ex) {
$this->callWizard($ex->getMessage(), true, 'error');
}
@ -3909,13 +3902,23 @@ class mail_ui
* if other than active profile; nothing is done!
* @return nothing
*/
function ajax_refreshVacationNotice($icServerID=null)
public static function ajax_refreshVacationNotice($icServerID=null)
{
//error_log(__METHOD__.__LINE__.array2string($icServerId));
if (empty($icServerID)) $icServerID = $this->mail_bo->profileID;
if ($icServerID != $this->mail_bo->profileID) return;
$vacation = $this->gatherVacation();
//error_log(__METHOD__.__LINE__.array2string($vacation));
//Get vacation from cache if it's available
$cachedVacations = egw_cache::getCache(egw_cache::INSTANCE, 'email', 'vacationNotice'+$GLOBALS['egw_info']['user']['account_lid']);
$vacation = $cachedVacations[$icServerID];
if (!$vacation)
{
// Create mail app object
$mail = new mail_ui();
if (empty($icServerID)) $icServerID = $mail->mail_bo->profileID;
if ($icServerID != $mail->mail_bo->profileID) return;
$vacation = $mail->gatherVacation($cachedVacations);
}
if($vacation) {
if (is_array($vacation) && ($vacation['status'] == 'on' || $vacation['status']=='by_date'))
{