[gnome-software/gnome-3-20] Do not maintain a cache of applications in the plugin loader



commit fe46d5f4be30fa4ef64740c5bf65eb48fe45b5c8
Author: Richard Hughes <richard hughsie com>
Date:   Wed Mar 23 09:48:10 2016 +0000

    Do not maintain a cache of applications in the plugin loader
    
    We don't actually need this now.

 src/gs-plugin-loader-sync.c |    1 -
 src/gs-plugin-loader.c      |  128 -------------------------------------------
 src/gs-plugin-loader.h      |    2 -
 src/gs-self-test.c          |   28 +---------
 4 files changed, 1 insertions(+), 158 deletions(-)
---
diff --git a/src/gs-plugin-loader-sync.c b/src/gs-plugin-loader-sync.c
index 254b8b9..ce0b9c2 100644
--- a/src/gs-plugin-loader-sync.c
+++ b/src/gs-plugin-loader-sync.c
@@ -37,7 +37,6 @@ gs_plugin_loader_get_app_by_id (GsPluginLoader *plugin_loader,
        gboolean ret;
 
        app = gs_app_new (id);
-       app = gs_plugin_loader_dedupe (plugin_loader, app);
        ret = gs_plugin_loader_app_refine (plugin_loader, app, flags,
                                           cancellable, error);
        if (!ret)
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index cc41712..4add2f5 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -43,8 +43,6 @@ typedef struct
        GMutex                   pending_apps_mutex;
        GPtrArray               *pending_apps;
 
-       GMutex                   app_cache_mutex;
-       GHashTable              *app_cache;
        GSettings               *settings;
 
        gchar                   **compatible_projects;
@@ -113,62 +111,6 @@ gs_plugin_loader_app_sort_cb (gconstpointer a, gconstpointer b)
 }
 
 /**
- * gs_plugin_loader_dedupe:
- */
-GsApp *
-gs_plugin_loader_dedupe (GsPluginLoader *plugin_loader, GsApp *app)
-{
-       GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
-       GsApp *new_app;
-       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->app_cache_mutex);
-
-       g_return_val_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader), NULL);
-       g_return_val_if_fail (GS_IS_APP (app), NULL);
-
-       /* not yet set */
-       if (gs_app_get_id (app) == NULL) {
-               return app;
-       }
-
-       /* already exists */
-       new_app = g_hash_table_lookup (priv->app_cache, gs_app_get_id (app));
-       if (new_app == app) {
-               return app;
-       }
-
-       /* insert new entry */
-       if (new_app == NULL) {
-               g_hash_table_insert (priv->app_cache,
-                                    g_strdup (gs_app_get_id (app)),
-                                    g_object_ref (app));
-               return app;
-       }
-
-       /* import all the useful properties */
-       gs_app_subsume (new_app, app);
-
-       /* this looks a little odd to unref the method parameter,
-        * but it allows us to do:
-        * app = gs_plugin_loader_dedupe (cache, app);
-        */
-       g_object_unref (app);
-       g_object_ref (new_app);
-
-       return new_app;
-}
-
-/**
- * gs_plugin_loader_list_dedupe:
- **/
-static void
-gs_plugin_loader_list_dedupe (GsPluginLoader *plugin_loader, GList *list)
-{
-       GList *l;
-       for (l = list; l != NULL; l = l->next)
-               l->data = gs_plugin_loader_dedupe (plugin_loader, GS_APP (l->data));
-}
-
-/**
  * gs_plugin_loader_run_refine:
  **/
 static gboolean
@@ -316,9 +258,6 @@ gs_plugin_loader_run_refine (GsPluginLoader *plugin_loader,
                                goto out;
                }
        }
-
-       /* dedupe applications we already know about */
-       gs_plugin_loader_list_dedupe (plugin_loader, *list);
 out:
        /* now emit all the changed signals */
        for (l = freeze_list; l != NULL; l = l->next)
@@ -391,9 +330,6 @@ gs_plugin_loader_run_results (GsPluginLoader *plugin_loader,
                gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
        }
 
-       /* dedupe applications we already know about */
-       gs_plugin_loader_list_dedupe (plugin_loader, list);
-
        /* run refine() on each one */
        ret = gs_plugin_loader_run_refine (plugin_loader,
                                           function_name,
@@ -765,9 +701,6 @@ gs_plugin_loader_get_updates_thread_cb (GTask *task,
        /* filter package list */
        gs_plugin_list_filter_duplicates (&state->list);
 
-       /* dedupe applications we already know about */
-       gs_plugin_loader_list_dedupe (plugin_loader, state->list);
-
        /* coalesce all packages down into one os-update */
        state->list = gs_plugin_loader_add_os_update_item (state->list);
 
@@ -878,9 +811,6 @@ gs_plugin_loader_get_distro_upgrades_thread_cb (GTask *task,
        /* filter package list */
        gs_plugin_list_filter_duplicates (&state->list);
 
-       /* dedupe applications we already know about */
-       gs_plugin_loader_list_dedupe (plugin_loader, state->list);
-
        /* success */
        g_task_return_pointer (task, gs_plugin_list_copy (state->list), (GDestroyNotify) gs_plugin_list_free);
 }
@@ -961,9 +891,6 @@ gs_plugin_loader_get_unvoted_reviews_thread_cb (GTask *task,
        /* filter package list */
        gs_plugin_list_filter_duplicates (&state->list);
 
-       /* dedupe applications we already know about */
-       gs_plugin_loader_list_dedupe (plugin_loader, state->list);
-
        /* success */
        g_task_return_pointer (task, gs_plugin_list_copy (state->list), (GDestroyNotify) gs_plugin_list_free);
 }
@@ -1044,9 +971,6 @@ gs_plugin_loader_get_sources_thread_cb (GTask *task,
        /* filter package list */
        gs_plugin_list_filter_duplicates (&state->list);
 
-       /* dedupe applications we already know about */
-       gs_plugin_loader_list_dedupe (plugin_loader, state->list);
-
        /* none left? */
        if (state->list == NULL) {
                g_task_return_new_error (task,
@@ -1545,9 +1469,6 @@ gs_plugin_loader_search_thread_cb (GTask *task,
                gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
        }
 
-       /* dedupe applications we already know about */
-       gs_plugin_loader_list_dedupe (plugin_loader, state->list);
-
        /* run refine() on each one */
        ret = gs_plugin_loader_run_refine (plugin_loader,
                                           function_name,
@@ -1709,9 +1630,6 @@ gs_plugin_loader_search_files_thread_cb (GTask *task,
                gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
        }
 
-       /* dedupe applications we already know about */
-       gs_plugin_loader_list_dedupe (plugin_loader, state->list);
-
        /* run refine() on each one */
        ret = gs_plugin_loader_run_refine (plugin_loader,
                                           function_name,
@@ -1874,9 +1792,6 @@ gs_plugin_loader_search_what_provides_thread_cb (GTask *task,
                gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
        }
 
-       /* dedupe applications we already know about */
-       gs_plugin_loader_list_dedupe (plugin_loader, state->list);
-
        /* run refine() on each one */
        ret = gs_plugin_loader_run_refine (plugin_loader,
                                           function_name,
@@ -2178,9 +2093,6 @@ gs_plugin_loader_get_category_apps_thread_cb (GTask *task,
                gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
        }
 
-       /* dedupe applications we already know about */
-       gs_plugin_loader_list_dedupe (plugin_loader, state->list);
-
        /* run refine() on each one */
        ret = gs_plugin_loader_run_refine (plugin_loader,
                                           function_name,
@@ -2561,12 +2473,6 @@ load_install_queue (GsPluginLoader *plugin_loader, GError **error)
                app = gs_app_new (names[i]);
                gs_app_set_state (app, AS_APP_STATE_QUEUED_FOR_INSTALL);
 
-               g_mutex_lock (&priv->app_cache_mutex);
-               g_hash_table_insert (priv->app_cache,
-                                    g_strdup (gs_app_get_id (app)),
-                                    g_object_ref (app));
-               g_mutex_unlock (&priv->app_cache_mutex);
-
                g_mutex_lock (&priv->pending_apps_mutex);
                g_ptr_array_add (priv->pending_apps,
                                 g_object_ref (app));
@@ -2966,30 +2872,6 @@ gs_plugin_loader_updates_changed_delay_cb (gpointer user_data)
 {
        GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (user_data);
        GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
-       GList *apps;
-       GList *l;
-       GsApp *app;
-
-       /* no longer know the state of these */
-       g_mutex_lock (&priv->app_cache_mutex);
-       apps = g_hash_table_get_values (priv->app_cache);
-       for (l = apps; l != NULL; l = l->next) {
-               app = GS_APP (l->data);
-               switch (gs_app_get_state (app)) {
-               case AS_APP_STATE_INSTALLED:
-               case AS_APP_STATE_UPDATABLE:
-               case AS_APP_STATE_UPDATABLE_LIVE:
-                       gs_app_set_state (app, AS_APP_STATE_UNKNOWN);
-                       break;
-               default:
-                       break;
-               }
-       }
-       g_list_free (apps);
-
-       /* not valid anymore */
-       g_hash_table_remove_all (priv->app_cache);
-       g_mutex_unlock (&priv->app_cache_mutex);
 
        /* notify shells */
        g_debug ("updates-changed");
@@ -3396,7 +3278,6 @@ gs_plugin_loader_dispose (GObject *object)
        g_clear_object (&priv->soup_session);
        g_clear_object (&priv->profile);
        g_clear_object (&priv->settings);
-       g_clear_pointer (&priv->app_cache, g_hash_table_unref);
        g_clear_pointer (&priv->pending_apps, g_ptr_array_unref);
 
        G_OBJECT_CLASS (gs_plugin_loader_parent_class)->dispose (object);
@@ -3417,7 +3298,6 @@ gs_plugin_loader_finalize (GObject *object)
        g_free (priv->locale);
 
        g_mutex_clear (&priv->pending_apps_mutex);
-       g_mutex_clear (&priv->app_cache_mutex);
 
        G_OBJECT_CLASS (gs_plugin_loader_parent_class)->finalize (object);
 }
@@ -3472,10 +3352,6 @@ gs_plugin_loader_init (GsPluginLoader *plugin_loader)
        priv->pending_apps = g_ptr_array_new_with_free_func ((GFreeFunc) g_object_unref);
        priv->profile = as_profile_new ();
        priv->settings = g_settings_new ("org.gnome.software");
-       priv->app_cache = g_hash_table_new_full (g_str_hash,
-                                                               g_str_equal,
-                                                               g_free,
-                                                               (GFreeFunc) g_object_unref);
 
        /* share a soup session (also disable the double-compression) */
        priv->soup_session = soup_session_new_with_options (SOUP_SESSION_USER_AGENT, gs_user_agent (),
@@ -3493,7 +3369,6 @@ gs_plugin_loader_init (GsPluginLoader *plugin_loader)
                *match = '\0';
 
        g_mutex_init (&priv->pending_apps_mutex);
-       g_mutex_init (&priv->app_cache_mutex);
 
        /* by default we only show project-less apps or compatible projects */
        tmp = g_getenv ("GNOME_SOFTWARE_COMPATIBLE_PROJECTS");
@@ -3781,9 +3656,6 @@ gs_plugin_loader_filename_to_app_thread_cb (GTask *task,
                gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
        }
 
-       /* dedupe applications we already know about */
-       gs_plugin_loader_list_dedupe (plugin_loader, state->list);
-
        /* run refine() on each one */
        ret = gs_plugin_loader_run_refine (plugin_loader,
                                           function_name,
diff --git a/src/gs-plugin-loader.h b/src/gs-plugin-loader.h
index 2365cb0..f1a2d8c 100644
--- a/src/gs-plugin-loader.h
+++ b/src/gs-plugin-loader.h
@@ -237,8 +237,6 @@ void                 gs_plugin_loader_refresh_async         (GsPluginLoader 
*plugin_loader,
                                                         GAsyncReadyCallback callback,
                                                         gpointer        user_data);
 GPtrArray      *gs_plugin_loader_get_pending           (GsPluginLoader *plugin_loader);
-GsApp          *gs_plugin_loader_dedupe                (GsPluginLoader *plugin_loader,
-                                                        GsApp          *app);
 void            gs_plugin_loader_set_network_status    (GsPluginLoader *plugin_loader,
                                                         gboolean        online);
 gboolean        gs_plugin_loader_get_plugin_supported  (GsPluginLoader *plugin_loader,
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index ebcc440..4e915e4 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2013 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2013-2016 Richard Hughes <richard hughsie com>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -144,31 +144,6 @@ gs_plugin_loader_status_changed_cb (GsPluginLoader *plugin_loader,
 }
 
 static void
-gs_plugin_loader_dedupe_func (void)
-{
-       g_autoptr(GsApp) app1 = NULL;
-       g_autoptr(GsApp) app2 = NULL;
-       g_autoptr(GsPluginLoader) loader = NULL;
-
-       loader = gs_plugin_loader_new ();
-
-       /* add app */
-       app1 = gs_app_new ("app1");
-       gs_app_set_description (app1, GS_APP_QUALITY_NORMAL, "description");
-       app1 = gs_plugin_loader_dedupe (loader, app1);
-       g_assert_cmpstr (gs_app_get_id (app1), ==, "app1");
-       g_assert_cmpstr (gs_app_get_description (app1), ==, "description");
-
-       app2 = gs_app_new ("app1");
-       app2 = gs_plugin_loader_dedupe (loader, app2);
-       g_assert_cmpstr (gs_app_get_id (app2), ==, "app1");
-       g_assert_cmpstr (gs_app_get_description (app2), ==, "description");
-       app2 = gs_plugin_loader_dedupe (loader, app2);
-       g_assert_cmpstr (gs_app_get_id (app2), ==, "app1");
-       g_assert_cmpstr (gs_app_get_description (app2), ==, "description");
-}
-
-static void
 gs_plugin_loader_func (void)
 {
        gboolean ret;
@@ -516,7 +491,6 @@ main (int argc, char **argv)
        g_test_add_func ("/gnome-software/app{subsume}", gs_app_subsume_func);
        if (g_getenv ("HAS_APPSTREAM") != NULL)
                g_test_add_func ("/gnome-software/plugin-loader{empty}", gs_plugin_loader_empty_func);
-       g_test_add_func ("/gnome-software/plugin-loader{dedupe}", gs_plugin_loader_dedupe_func);
        if(0)g_test_add_func ("/gnome-software/plugin-loader", gs_plugin_loader_func);
        if(0)g_test_add_func ("/gnome-software/plugin-loader{webapps}", gs_plugin_loader_webapps_func);
 


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