From 73c1f064b989a606ffd1257dfa971ef7aa3367f4 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Mon, 28 Jul 2014 21:21:23 +0000 Subject: [PATCH] Don't send mail rows when opening mail app, but use client side cache instead. Gives large speed improvements when changing to previously opened folders. --- mail/inc/class.mail_ui.inc.php | 2 ++ mail/js/app.js | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/mail/inc/class.mail_ui.inc.php b/mail/inc/class.mail_ui.inc.php index 8d34dd236e..c5717fc10a 100644 --- a/mail/inc/class.mail_ui.inc.php +++ b/mail/inc/class.mail_ui.inc.php @@ -421,6 +421,8 @@ class mail_ui ); } } + + $content[self::$nm_index]['num_rows'] = 0; // Do not send any rows with initial request $content[self::$nm_index]['default_cols'] = 'status,attachments,subject,address,date,size'; // I columns to use if there's no user or default pref (! as first char uses all but the named columns), default all columns $content[self::$nm_index]['csv_fields'] = false; if ($msg) diff --git a/mail/js/app.js b/mail/js/app.js index ea1d711f79..9e0a625df1 100644 --- a/mail/js/app.js +++ b/mail/js/app.js @@ -65,6 +65,11 @@ app.classes.mail = AppJS.extend( */ init: function() { this._super.apply(this,arguments); + + // Turn on client side, persistent cache + // egw.data system runs encapsulated below etemplate, so this must be + // done before the nextmatch is created. + this.egw.dataCacheRegister('mail',this.nm_cache, this); }, /** @@ -81,6 +86,10 @@ app.classes.mail = AppJS.extend( $j(nm).off('refresh'); } } + + // Unregister client side cache + this.egw.dataCacheUnregister('mail'); + delete this.et2_obj; // call parent this._super.apply(this, arguments); @@ -255,6 +264,32 @@ app.classes.mail = AppJS.extend( } }, + /** + * Callback function for dataFetch caching. + * + * We only cache the first chunk (50 rows), and only if search filter is not set, + * but we cache this for every combination of folder, filter & filter2. + * + * @param {object} query_context Query information from egw.dataFetch() + * @returns {string|false} Cache key, or false to not cache + */ + nm_cache: function(query_context) + { + // Only cache first chunk of rows, if no search filter + if((!query_context || !query_context.start) && query_context.count == 0 && !( + query_context.self._filters.search || false) + ) + { + // Make sure keys match, even if some filters are not defined + return JSON.stringify({ + selectedFolder: query_context.self._filters.selectedFolder || '', + filter: query_context.self._filters.filter || '', + filter2: query_context.self._filters.filter2 + }); + } + return false; + }, + /** * mail rebuild Action menu On nm-list *