Skip to content

Commit

Permalink
Resolve the-djmaze#891 and other index cache issues
Browse files Browse the repository at this point in the history
  • Loading branch information
the-djmaze committed Feb 3, 2023
1 parent 11c5b0e commit 16daa7b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .docker/release/files/usr/local/include/application.ini
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ http_expires = 3600
; Caching message UIDs when searching and sorting (threading)
server_uids = On

system_data = On

[imap]
use_force_selection = Off
use_expunge_all_on_delete = Off
Expand All @@ -266,7 +268,6 @@ message_all_headers = Off
show_login_alert = On

[labs]
cache_system_data = On
date_from_headers = On
allow_message_append = Off
login_fault_delay = 1
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
**Editing HTML Template Files**

1. Edit data/\_data_/\_default_/configs/application.ini
2. Set 'cache_system_data' to Off
2. Set `[cache] system_data` to Off

**Release**

Expand Down
13 changes: 9 additions & 4 deletions snappymail/v/0.0.0/app/libraries/RainLoop/Config/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,19 @@ public function Set(string $sSectionKey, string $sParamKey, $mParamValue) : void
{
// Workarounds for the changed application structure
if ('labs' === $sSectionKey) {
if (\str_contains($sParamKey, 'imap_')) {
if (\str_starts_with($sParamKey, 'imap_')) {
$sSectionKey = 'imap';
$sParamKey = \str_replace('imap_', '', $sParamKey);
}
if (\str_contains($sParamKey, 'use_app_debug_')) {
if (\str_starts_with($sParamKey, 'use_app_debug_')) {
$sSectionKey = 'debug';
$sParamKey = \str_replace('use_app_debug_js', 'javascript', $sParamKey);
$sParamKey = \str_replace('use_app_debug_css', 'css', $sParamKey);
}
if ('cache_system_data' === $sParamKey) {
$sSectionKey = 'cache';
$sParamKey = 'system_data';
}
}
parent::Set($sSectionKey, $sParamKey, $mParamValue);
}
Expand Down Expand Up @@ -363,7 +367,9 @@ protected function defaultValues() : array
'http' => array(true, 'Browser-level cache. If enabled, caching is maintainted without using files'),
'http_expires' => array(3600, 'Browser-level cache time (seconds, Expires header)'),

'server_uids' => array(true, 'Caching message UIDs when searching and sorting (threading)')
'server_uids' => array(true, 'Caching message UIDs when searching and sorting (threading)'),

'system_data' => array(true)
),

'imap' => array(
Expand All @@ -376,7 +382,6 @@ protected function defaultValues() : array
),

'labs' => array(
'cache_system_data' => array(true),
'date_from_headers' => array(true, 'Display message RFC 2822 date and time header, instead of the arrival internal date.'),
'allow_message_append' => array(false),
'login_fault_delay' => array(1),
Expand Down
24 changes: 12 additions & 12 deletions snappymail/v/0.0.0/app/libraries/RainLoop/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,25 +150,21 @@ private static function RunResult() : bool

$oActions = Api::Actions();

$sThemeName = $oActions->GetTheme($bAdmin);

$aTemplateParameters = array(
'{{BaseAppThemeName}}' => $sThemeName,
'{{BaseAppFaviconPngLinkTag}}' => $sFaviconPngLink ? '<link type="image/png" rel="shortcut icon" href="'.$sFaviconPngLink.'">' : '',
'{{BaseAppFaviconTouchLinkTag}}' => $sAppleTouchLink ? '<link type="image/png" rel="apple-touch-icon" href="'.$sAppleTouchLink.'">' : '',
'{{BaseAppMainCssLink}}' => Utils::WebStaticPath('css/'.($bAdmin ? 'admin' : 'app').$sAppCssMin.'.css'),
'{{BaseAppManifestLink}}' => Utils::WebStaticPath('manifest.json'),
'{{BaseFavIconSvg}}' => $sFaviconUrl ? '' : Utils::WebStaticPath('favicon.svg'),
'{{LoadingDescriptionEsc}}' => \htmlspecialchars($oConfig->Get('webmail', 'loading_description', 'SnappyMail'), ENT_QUOTES|ENT_IGNORE, 'UTF-8'),
'{{BaseAppAdmin}}' => $bAdmin ? 1 : 0,

'{{NO_SCRIPT_DESC}}' => \nl2br($oActions->StaticI18N('NO_SCRIPT_TITLE') . "\n" . $oActions->StaticI18N('NO_SCRIPT_DESC')),
'{{NO_COOKIE_TITLE}}' => $oActions->StaticI18N('NO_COOKIE_TITLE'),
'{{NO_COOKIE_DESC}}' => $oActions->StaticI18N('NO_COOKIE_DESC'),
'{{BAD_BROWSER_TITLE}}' => $oActions->StaticI18N('BAD_BROWSER_TITLE'),
'{{BAD_BROWSER_DESC}}' => \nl2br($oActions->StaticI18N('BAD_BROWSER_DESC'))
'{{BaseAppAdmin}}' => $bAdmin ? 1 : 0
);

$sCacheFileName = '';
if ($oConfig->Get('labs', 'cache_system_data', true)) {
$sCacheFileName = 'TMPL:' . $sLanguage . \md5(
if ($oConfig->Get('cache', 'system_data', true)) {
$sCacheFileName = 'TMPL:' . $sLanguage . \sha1(
Utils::jsonEncode(array(
$oConfig->Get('cache', 'index', ''),
$oActions->Plugins()->Hash(),
Expand All @@ -184,13 +180,17 @@ private static function RunResult() : bool
if ($sResult) {
$sResult .= '<!--cached-->';
} else {
$sThemeName = $oActions->GetTheme($bAdmin);
$aTemplateParameters['{{BaseAppBootCss}}'] = \file_get_contents(APP_VERSION_ROOT_PATH.'static/css/boot'.$sAppCssMin.'.css');
$aTemplateParameters['{{BaseAppBootScript}}'] = \file_get_contents(APP_VERSION_ROOT_PATH.'static/js'.($sAppJsMin ? '/min' : '').'/boot'.$sAppJsMin.'.js');
$aTemplateParameters['{{BaseAppThemeName}}'] = $sThemeName;
$aTemplateParameters['{{BaseAppMainCssLink}}'] = Utils::WebStaticPath('css/'.($bAdmin ? 'admin' : 'app').$sAppCssMin.'.css');
$aTemplateParameters['{{BaseAppThemeCss}}'] = \preg_replace('/\\s*([:;{},]+)\\s*/s', '$1', $oActions->compileCss($sThemeName, $bAdmin));
$aTemplateParameters['{{BaseLanguage}}'] = $oActions->compileLanguage($sLanguage, $bAdmin);
$aTemplateParameters['{{BaseTemplates}}'] = Utils::ClearHtmlOutput($oServiceActions->compileTemplates($bAdmin));
$aTemplateParameters['{{NO_SCRIPT_DESC}}'] = \nl2br($oActions->StaticI18N('NO_SCRIPT_TITLE') . "\n" . $oActions->StaticI18N('NO_SCRIPT_DESC'));
$aTemplateParameters['{{NO_COOKIE_TITLE}}'] = $oActions->StaticI18N('NO_COOKIE_TITLE');
$aTemplateParameters['{{NO_COOKIE_DESC}}'] = $oActions->StaticI18N('NO_COOKIE_DESC');
$aTemplateParameters['{{BAD_BROWSER_TITLE}}'] = $oActions->StaticI18N('BAD_BROWSER_TITLE');
$aTemplateParameters['{{BAD_BROWSER_DESC}}'] = \nl2br($oActions->StaticI18N('BAD_BROWSER_DESC'));
$sResult = Utils::ClearHtmlOutput(\file_get_contents(APP_VERSION_ROOT_PATH.'app/templates/Index.html'));
$sResult = \strtr($sResult, $aTemplateParameters);
if ($sCacheFileName) {
Expand Down
6 changes: 3 additions & 3 deletions snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public function ServiceLang() : string
$bAdmin = 'Admin' === (isset($this->aPaths[2]) ? (string) $this->aPaths[2] : 'App');
$sLanguage = $this->oActions->ValidateLanguage($this->aPaths[3], '', $bAdmin);

$bCacheEnabled = $this->Config()->Get('labs', 'cache_system_data', true);
$bCacheEnabled = $this->Config()->Get('cache', 'system_data', true);
if (!empty($sLanguage) && $bCacheEnabled) {
$this->oActions->verifyCacheByKey($this->sQuery);
}
Expand Down Expand Up @@ -460,7 +460,7 @@ public function ServicePlugins() : string
$bAppDebug = $this->Config()->Get('debug', 'enable', false);
$sMinify = ($bAppDebug || $this->Config()->Get('debug', 'javascript', false)) ? '' : 'min';

$bCacheEnabled = !$bAppDebug && $this->Config()->Get('labs', 'cache_system_data', true);
$bCacheEnabled = !$bAppDebug && $this->Config()->Get('cache', 'system_data', true);
if ($bCacheEnabled) {
$this->oActions->verifyCacheByKey($this->sQuery . $sMinify);
}
Expand Down Expand Up @@ -504,7 +504,7 @@ public function ServiceCss() : string
$bAppDebug = $this->Config()->Get('debug', 'enable', false);
$sMinify = ($bAppDebug || $this->Config()->Get('debug', 'css', false)) ? '' : 'min';

$bCacheEnabled = !$bAppDebug && $this->Config()->Get('labs', 'cache_system_data', true);
$bCacheEnabled = !$bAppDebug && $this->Config()->Get('cache', 'system_data', true);
if ($bCacheEnabled) {
$this->oActions->verifyCacheByKey($this->sQuery . $sMinify);
}
Expand Down

0 comments on commit 16daa7b

Please sign in to comment.