From 70159c1897125e03b835dfb5d0ff77eb642f455c Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 16 Apr 2010 15:00:04 -0600 Subject: [PATCH] Optimize updateFlag() for search mailboxes with a large number of updated messages --- imp/js/DimpBase.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/imp/js/DimpBase.js b/imp/js/DimpBase.js index ff9cd9757..49369c6df 100644 --- a/imp/js/DimpBase.js +++ b/imp/js/DimpBase.js @@ -2810,20 +2810,29 @@ var DimpBase = { updateFlag: function(vs, flag, add) { + var s = {}; add = this.convertFlag(flag, add); vs.get('dataob').each(function(ob) { this._updateFlag(ob, flag, add); - /* If this is a search mailbox, also need to update flag in base - * view, if it is in the buffer. */ if (this.isSearch()) { - var tmp = this.viewport.getSelection(ob.view).search({ imapuid: { equal: [ ob.imapuid ] }, view: { equal: [ ob.view ] } }); - if (tmp.size()) { - this._updateFlag(tmp.get('dataob').first(), flag, add); + if (s[ob.view]) { + s[ob.view].push(ob.imapuid); + } else { + s[ob.view] = [ ob.imapuid ]; } } }, this); + + /* If this is a search mailbox, also need to update flag in base view, + * if it is in the buffer. */ + $H(s).each(function(m) { + var tmp = this.viewport.getSelection(m.key).search({ imapuid: { equal: m.value }, view: { equal: m.key } }); + if (tmp.size()) { + this._updateFlag(tmp.get('dataob').first(), flag, add); + } + }, this); }, _updateFlag: function(ob, flag, add) -- 2.11.0