appDisplay: Reduce g_app_info_get_all() calls

Whenever the AllView needs (re)populating, we used to do one general
g_app_info_get_all() to get all GAppInfo, plus one per app folder in order
to check the ones that fall within that category. This calls results in a
fair amount of I/O blocking the main loop.

In order to ease this, keep the GAppInfo list around in AllView, and make
the AppFolders use it when figuring out the contained apps. Since reloading
the AllView results in AppFolders regenerated from scratch, the app info
list is ensured to be up-to-date for any later change within the AppFolder
(eg. through the GSettings key changing).

As the list was already filtered in the first place, we can also remove
the try{}catch() in AppFolder in order to discard desktop files with
invalid encoding.

Related: https://gitlab.gnome.org/GNOME/gnome-shell/issues/832
This commit is contained in:
Carlos Garnacho 2018-12-03 13:18:19 +01:00
parent 38805ae662
commit 3db52155dd

View File

@ -487,15 +487,21 @@ var AllView = class AllView extends BaseAppView {
});
}
getAppInfos() {
return this._appInfoList;
}
_loadApps() {
let apps = Gio.AppInfo.get_all().filter(appInfo => {
this._appInfoList = Gio.AppInfo.get_all().filter(appInfo => {
try {
let id = appInfo.get_id(); // catch invalid file encodings
} catch(e) {
return false;
}
return appInfo.should_show();
}).map(app => app.get_id());
});
let apps = this._appInfoList.map(app => app.get_id());
let appSys = Shell.AppSystem.get_default();
@ -1298,15 +1304,13 @@ var FolderIcon = class FolderIcon {
folderApps.forEach(addAppId);
let folderCategories = this._folder.get_strv('categories');
Gio.AppInfo.get_all().forEach(appInfo => {
let appInfos = this._parentView.getAppInfos();
appInfos.forEach(appInfo => {
let appCategories = _getCategories(appInfo);
if (!_listsIntersect(folderCategories, appCategories))
return;
try {
addAppId(appInfo.get_id()); // catch invalid file encodings
} catch(e) {
}
addAppId(appInfo.get_id());
});
this.actor.visible = this.view.getAllItems().length > 0;