From 16daa7b55e211a7da0373dbe6ebe8cf3ff47dd0e Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Fri, 3 Feb 2023 09:20:42 +0100 Subject: [PATCH] Resolve #891 and other index cache issues --- .../files/usr/local/include/application.ini | 3 ++- CONTRIBUTING.md | 2 +- .../libraries/RainLoop/Config/Application.php | 13 ++++++---- .../0.0.0/app/libraries/RainLoop/Service.php | 24 +++++++++---------- .../app/libraries/RainLoop/ServiceActions.php | 6 ++--- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/.docker/release/files/usr/local/include/application.ini b/.docker/release/files/usr/local/include/application.ini index 034224d54..86703ab5a 100644 --- a/.docker/release/files/usr/local/include/application.ini +++ b/.docker/release/files/usr/local/include/application.ini @@ -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 @@ -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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index db363fddd..95821f69d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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** diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Config/Application.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Config/Application.php index 41f1b49f6..b8cfe4f81 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Config/Application.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Config/Application.php @@ -93,15 +93,19 @@ class Application extends \RainLoop\Config\AbstractConfig { // 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); } @@ -363,7 +367,9 @@ Enables caching in the system'), '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( @@ -376,7 +382,6 @@ Enables caching in the system'), ), '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), diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Service.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Service.php index 3b52d6e92..1abc3d7dd 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Service.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Service.php @@ -150,25 +150,21 @@ abstract class Service $oActions = Api::Actions(); + $sThemeName = $oActions->GetTheme($bAdmin); + $aTemplateParameters = array( + '{{BaseAppThemeName}}' => $sThemeName, '{{BaseAppFaviconPngLinkTag}}' => $sFaviconPngLink ? '' : '', '{{BaseAppFaviconTouchLinkTag}}' => $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(), @@ -184,13 +180,17 @@ abstract class Service if ($sResult) { $sResult .= ''; } 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) { diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php index 3f3d7b556..20758d2d2 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php @@ -422,7 +422,7 @@ class ServiceActions $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); } @@ -460,7 +460,7 @@ class ServiceActions $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); } @@ -504,7 +504,7 @@ class ServiceActions $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); }