[gnome-software] trivial: Never add duplicate wildcard apps to the GsAppList



commit 0bdb83d7a7f10590fea84f25a6d4e39c0c577984
Author: Richard Hughes <richard hughsie com>
Date:   Thu Sep 27 16:43:02 2018 +0100

    trivial: Never add duplicate wildcard apps to the GsAppList
    
    This makes getting the alternates list more performant, as we don't call into
    the plugins multiple times with the same application ID.

 lib/gs-app-list.c  | 16 ++++++++++++++++
 lib/gs-self-test.c | 13 +++++++++++++
 2 files changed, 29 insertions(+)
---
diff --git a/lib/gs-app-list.c b/lib/gs-app-list.c
index db3c7452..b0acd70d 100644
--- a/lib/gs-app-list.c
+++ b/lib/gs-app-list.c
@@ -304,6 +304,22 @@ gs_app_list_check_for_duplicate (GsAppList *list, GsApp *app)
        const gchar *id;
        const gchar *id_old = NULL;
 
+       /* adding a wildcard */
+       if (gs_app_has_quirk (app, AS_APP_QUIRK_MATCH_ANY_PREFIX)) {
+               for (guint i = 0; i < list->array->len; i++) {
+                       GsApp *app_tmp = g_ptr_array_index (list->array, i);
+                       if (!gs_app_has_quirk (app, AS_APP_QUIRK_MATCH_ANY_PREFIX))
+                               continue;
+                       if (g_strcmp0 (gs_app_get_unique_id (app_tmp),
+                                      gs_app_get_unique_id (app)) == 0) {
+                               g_debug ("not adding exactly the same wildcard %s",
+                                        gs_app_get_unique_id (app_tmp));
+                               return FALSE;
+                       }
+               }
+               return TRUE;
+       }
+
        /* does not exist */
        id = gs_app_get_unique_id (app);
        if (id == NULL) {
diff --git a/lib/gs-self-test.c b/lib/gs-self-test.c
index 868d5a50..6bc65976 100644
--- a/lib/gs-self-test.c
+++ b/lib/gs-self-test.c
@@ -460,6 +460,19 @@ gs_plugin_func (void)
        g_assert_cmpint (gs_app_list_length (list), ==, 2);
        g_object_unref (list);
 
+       /* allow duplicating a wildcard */
+       list = gs_app_list_new ();
+       app = gs_app_new ("gimp.desktop");
+       gs_app_add_quirk (app, AS_APP_QUIRK_MATCH_ANY_PREFIX);
+       gs_app_list_add (list, app);
+       g_object_unref (app);
+       app = gs_app_new ("gimp.desktop");
+       gs_app_add_quirk (app, AS_APP_QUIRK_MATCH_ANY_PREFIX);
+       gs_app_list_add (list, app);
+       g_object_unref (app);
+       g_assert_cmpint (gs_app_list_length (list), ==, 1);
+       g_object_unref (list);
+
        /* add a list to a list */
        list = gs_app_list_new ();
        list_dup = gs_app_list_new ();


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