[gnome-shell/gbsneto/cache-folder-apps] appDisplay: Cache app ids in FolderView




commit f34ffddd8a2084fa40851a4c685bdc3b9773e441
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Aug 13 20:20:52 2020 -0300

    appDisplay: Cache app ids in FolderView
    
    Instead of reading a GSettings and building the app ids list
    every single time FolderView needs to check for something,
    cache it before redisplay and reuse this cached list everywhere.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1408

 js/ui/appDisplay.js | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 1c25dfe39b..c1fb1cb201 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -1604,6 +1604,7 @@ class FolderView extends BaseAppView {
         action.connect('pan', this._onPan.bind(this));
         this._scrollView.add_action(action);
 
+        this._appIds = [];
         this._redisplay();
     }
 
@@ -1649,8 +1650,7 @@ class FolderView extends BaseAppView {
     }
 
     _getItemPosition(item) {
-        const appIds = this._getFolderApps();
-        const appIndex = appIds.indexOf(item.id);
+        const appIndex = this._appIds.indexOf(item.id);
 
         if (appIndex === -1)
             return [-1, -1];
@@ -1660,10 +1660,8 @@ class FolderView extends BaseAppView {
     }
 
     _compareItems(a, b) {
-        const appIds = this._getFolderApps();
-
-        const aPosition = appIds.indexOf(a.id);
-        const bPosition = appIds.indexOf(b.id);
+        const aPosition = this._appIds.indexOf(a.id);
+        const bPosition = this._appIds.indexOf(b.id);
 
         if (aPosition === -1 && bPosition === -1)
             return a.name.localeCompare(b.name);
@@ -1720,9 +1718,8 @@ class FolderView extends BaseAppView {
     _loadApps() {
         let apps = [];
         let appSys = Shell.AppSystem.get_default();
-        const appIds = this._getFolderApps();
 
-        appIds.forEach(appId => {
+        this._appIds.forEach(appId => {
             const app = appSys.lookup_app(appId);
 
             let icon = this._items.get(appId);
@@ -1735,6 +1732,13 @@ class FolderView extends BaseAppView {
         return apps;
     }
 
+    _redisplay() {
+        // Keep the app ids list cached
+        this._appIds = this._getFolderApps();
+
+        super._redisplay();
+    }
+
     acceptDrop(source) {
         if (!super.acceptDrop(source))
             return false;


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