[gnome-software] Do not unconditionally refine AppStream apps in the cache



commit 0270f8a6430befb24d11172c47beb1dfe8d0d445
Author: Richard Hughes <richard hughsie com>
Date:   Wed Sep 28 09:45:18 2016 +0100

    Do not unconditionally refine AppStream apps in the cache
    
    If the app is in the cache it does not need to be refined, so avoid doing a
    ton of string processing for no reason. This speeds up search performance.

 src/plugins/gs-appstream.c        |   12 +++++++-----
 src/plugins/gs-appstream.h        |    3 ++-
 src/plugins/gs-flatpak.c          |    4 +++-
 src/plugins/gs-plugin-appstream.c |   14 +++++++-------
 4 files changed, 19 insertions(+), 14 deletions(-)
---
diff --git a/src/plugins/gs-appstream.c b/src/plugins/gs-appstream.c
index 22a3f55..2e14458 100644
--- a/src/plugins/gs-appstream.c
+++ b/src/plugins/gs-appstream.c
@@ -28,7 +28,7 @@
 #define        GS_APPSTREAM_MAX_SCREENSHOTS    5
 
 GsApp *
-gs_appstream_create_app (GsPlugin *plugin, AsApp *item)
+gs_appstream_create_app (GsPlugin *plugin, AsApp *item, GError **error)
 {
        const gchar *unique_id = as_app_get_unique_id (item);
        GsApp *app = gs_plugin_cache_lookup (plugin, unique_id);
@@ -36,6 +36,8 @@ gs_appstream_create_app (GsPlugin *plugin, AsApp *item)
                app = gs_app_new (as_app_get_id (item));
                gs_app_set_metadata (app, "GnomeSoftware::Creator",
                                     gs_plugin_get_name (plugin));
+               if (!gs_appstream_refine_app (plugin, app, item, error))
+                       return NULL;
                gs_plugin_cache_add (plugin, unique_id, app);
        }
        return app;
@@ -795,8 +797,8 @@ gs_appstream_store_search_item (GsPlugin *plugin,
                return TRUE;
 
        /* create app */
-       app = gs_appstream_create_app (plugin, item);
-       if (!gs_appstream_refine_app (plugin, app, item, error))
+       app = gs_appstream_create_app (plugin, item, error);
+       if (app == NULL)
                return FALSE;
        gs_app_set_match_value (app, match_value);
        gs_app_list_add (list, app);
@@ -930,8 +932,8 @@ gs_appstream_store_add_category_apps (GsPlugin *plugin,
                                continue;
 
                        /* add all the data we can */
-                       app = gs_appstream_create_app (plugin, item);
-                       if (!gs_appstream_refine_app (plugin, app, item, error))
+                       app = gs_appstream_create_app (plugin, item, error);
+                       if (app == NULL)
                                return FALSE;
                        gs_app_list_add (list, app);
                }
diff --git a/src/plugins/gs-appstream.h b/src/plugins/gs-appstream.h
index 0a19fcf..88e8afc 100644
--- a/src/plugins/gs-appstream.h
+++ b/src/plugins/gs-appstream.h
@@ -27,7 +27,8 @@
 G_BEGIN_DECLS
 
 GsApp          *gs_appstream_create_app                (GsPlugin       *plugin,
-                                                        AsApp          *item);
+                                                        AsApp          *item,
+                                                        GError         **error);
 gboolean        gs_appstream_refine_app                (GsPlugin       *plugin,
                                                         GsApp          *app,
                                                         AsApp          *item,
diff --git a/src/plugins/gs-flatpak.c b/src/plugins/gs-flatpak.c
index c355ebf..d0c8857 100644
--- a/src/plugins/gs-flatpak.c
+++ b/src/plugins/gs-flatpak.c
@@ -1792,7 +1792,9 @@ gs_flatpak_refine_wildcard (GsFlatpak *self, GsApp *app,
                /* new app */
                g_debug ("found %s for wildcard %s",
                         as_app_get_unique_id (item), id);
-               new = gs_appstream_create_app (self->plugin, item);
+               new = gs_appstream_create_app (self->plugin, item, NULL);
+               if (new == NULL)
+                       return FALSE;
                gs_app_set_scope (new, self->scope);
                if (!gs_flatpak_refine_app (self, new, flags, cancellable, error))
                        return FALSE;
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index 29f85e1..1e620b6 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -409,11 +409,11 @@ gs_plugin_add_distro_upgrades (GsPlugin *plugin,
                        continue;
 
                /* create */
-               app = gs_appstream_create_app (plugin, item);
+               app = gs_appstream_create_app (plugin, item, error);
+               if (app == NULL)
+                       return FALSE;
                gs_app_set_kind (app, AS_APP_KIND_OS_UPGRADE);
                gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
-               if (!gs_appstream_refine_app (plugin, app, item, error))
-                       return FALSE;
                gs_app_list_add (list, app);
        }
        return TRUE;
@@ -477,8 +477,8 @@ gs_plugin_refine_wildcard (GsPlugin *plugin,
                /* new app */
                g_debug ("found %s for wildcard %s",
                         as_app_get_id (item), id);
-               new = gs_appstream_create_app (plugin, item);
-               if (!gs_appstream_refine_app (plugin, new, item, error))
+               new = gs_appstream_create_app (plugin, item, error);
+               if (new == NULL)
                        return FALSE;
                gs_app_list_add (list, new);
        }
@@ -540,8 +540,8 @@ gs_plugin_add_installed (GsPlugin *plugin,
                item = g_ptr_array_index (array, i);
                if (as_app_get_state (item) == AS_APP_STATE_INSTALLED) {
                        g_autoptr(GsApp) app = NULL;
-                       app = gs_appstream_create_app (plugin, item);
-                       if (!gs_appstream_refine_app (plugin, app, item, error))
+                       app = gs_appstream_create_app (plugin, item, error);
+                       if (app == NULL)
                                return FALSE;
                        gs_app_list_add (list, app);
                }


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