allView, frequentView: Only create icons when necessary

The views (AllView and FrequentView) build a list of all applications
they contain. BaseView then diffs between what's currently added, and
what needs to be added, and removed.

This approach has a problem though: creating an AppIcon or a FolderIcon
connects to various signals, and we confuse the garbage collector.

When building the list of applications, instead of always creating new
icons, try to use already existing icons first.

Fixes https://gitlab.gnome.org/GNOME/gnome-shell/issues/1610
Fixes https://gitlab.gnome.org/GNOME/gnome-shell/issues/1694
This commit is contained in:
Georges Basile Stavracas Neto 2019-11-21 17:57:17 -03:00
parent acaa9f7f77
commit 910037f014

View File

@ -491,10 +491,15 @@ var AllView = GObject.registerClass({
let favoritesWritable = global.settings.is_writable('favorite-apps'); let favoritesWritable = global.settings.is_writable('favorite-apps');
apps.forEach(appId => { apps.forEach(appId => {
let icon = this._items[appId];
if (!icon) {
let app = appSys.lookup_app(appId); let app = appSys.lookup_app(appId);
let icon = new AppIcon(app, icon = new AppIcon(app, {
{ isDraggable: favoritesWritable }); isDraggable: favoritesWritable,
});
}
newApps.push(icon); newApps.push(icon);
}); });
@ -947,8 +952,12 @@ class FrequentView extends BaseAppView {
for (let i = 0; i < mostUsed.length; i++) { for (let i = 0; i < mostUsed.length; i++) {
if (!mostUsed[i].get_app_info().should_show()) if (!mostUsed[i].get_app_info().should_show())
continue; continue;
let appIcon = new AppIcon(mostUsed[i], let appIcon = this._items[mostUsed[i].get_id()];
{ isDraggable: favoritesWritable }); if (!appIcon) {
appIcon = new AppIcon(mostUsed[i], {
isDraggable: favoritesWritable,
});
}
apps.push(appIcon); apps.push(appIcon);
} }