[gnome-shell/zeitgeist] Don't refresh all the search providers in O(n^2) fashion; just refresh the one that changed



commit fb5a3a53fac37fc3f259a764d16ea02b9be7e614
Author: Seif Lotfy <seif lotfy com>
Date:   Fri Mar 4 16:42:15 2011 -0500

    Don't refresh all the search providers in O(n^2) fashion; just refresh the one that changed
    
    This modification reduces the faulty clearing and redrawing of the
    results.  The old code refreshed the view for every async
    search provider by iterating through all result sets (one result set per
    provider) and refreshing all providers. In this case there were 40
    redraws. This patch adds a new method _clearDisplayForProvider that
    allows us to refresh only providers with changed results.

 js/ui/searchDisplay.js |   27 ++++++++++++++++++++-------
 1 files changed, 20 insertions(+), 7 deletions(-)
---
diff --git a/js/ui/searchDisplay.js b/js/ui/searchDisplay.js
index 1290d23..5dc8bf7 100644
--- a/js/ui/searchDisplay.js
+++ b/js/ui/searchDisplay.js
@@ -190,9 +190,11 @@ SearchResults.prototype = {
         this._selectedProvider = -1;
         this._providers = this._searchSystem.getProviders();
         this._providerMeta = [];
-        for (let i = 0; i < this._providers.length; i++)
+        this._providerMetaResults = {};
+        for (let i = 0; i < this._providers.length; i++) {
             this.createProviderMeta(this._providers[i]);
-
+            this._providerMetaResults[this.providers[i].title] = [];
+        }
         this._searchProvidersBox = new St.BoxLayout({ style_class: 'search-providers-box' });
         this.actor.add(this._searchProvidersBox);
 
@@ -270,6 +272,12 @@ SearchResults.prototype = {
             meta.actor.hide();
         }
     },
+    
+    _clearDisplayForProvider: function(index) {
+        let meta = this._providerMeta[index];
+        meta.resultDisplay.clear();
+        meta.actor.hide();
+    },
 
     reset: function() {
         this._searchSystem.reset();
@@ -294,7 +302,6 @@ SearchResults.prototype = {
     },
 
     _updateResults: function(searchSystem, results) {
-        this._clearDisplay();
         if (results.length == 0) {
             this._statusText.set_text(_("No matching results."));
             this._statusText.show();
@@ -310,10 +317,16 @@ SearchResults.prototype = {
         for (let i = 0; i < results.length; i++) {
             let [provider, providerResults] = results[i];
             if (providerResults.length == 0)
-                  continue;
-            let meta = this._metaForProvider(provider);
-            meta.actor.show();
-            meta.resultDisplay.renderResults(providerResults, terms);
+                this._clearDisplayForProvider(i)
+            else {
+                if (this._providerMetaResults[provider.title] != providerResults) {
+                    this._providerMetaResults[provider.title] = providerResults;
+                    this._clearDisplayForProvider(i);
+                    let meta = this._metaForProvider(provider);
+                    meta.actor.show();
+                    meta.resultDisplay.renderResults(providerResults, terms);
+                }
+            }
         }
 
         if (this._selectedOpenSearchButton == -1)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]