[gnome-software] Do not use search using PackageKit by default
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Do not use search using PackageKit by default
- Date: Sat, 19 Oct 2013 19:25:35 +0000 (UTC)
commit 385774f65b3bdfd221080c9e53845e758c47a122
Author: Richard Hughes <richard hughsie com>
Date: Sat Oct 19 20:17:18 2013 +0100
Do not use search using PackageKit by default
We shouldn't actually need to do this, as all packages need to be converted to
applications using the AppStream metadata. The only time this is useful is when
the search term matches the package description and not the application
description, keyword, or the comment in the desktop file.
In this instance, the application should probably be shipping an AppData file
and be refined by the AppStream metadata. Consider it another reason to ship an
AppData file :)
This typically speeds up searching by more that 600ms per request.
src/plugins/Makefile.am | 9 ++
src/plugins/gs-plugin-packagekit-search.c | 157 +++++++++++++++++++++++++++++
src/plugins/gs-plugin-packagekit.c | 154 +----------------------------
src/plugins/packagekit-common.c | 104 +++++++++++++++++++
src/plugins/packagekit-common.h | 5 +
5 files changed, 276 insertions(+), 153 deletions(-)
---
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 89c2d29..a5ec830 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -39,6 +39,7 @@ plugin_LTLIBRARIES = \
libgs_plugin_fedora_tagger.la \
libgs_plugin_epiphany.la \
libgs_plugin_systemd-updates.la \
+ libgs_plugin_packagekit-search.la \
libgs_plugin_packagekit-refine.la \
libgs_plugin_packagekit-updates.la \
libgs_plugin_packagekit-offline.la \
@@ -141,6 +142,14 @@ libgs_plugin_packagekit_refine_la_LIBADD = $(GS_PLUGIN_LIBS) $(PACKAGEKIT_LIBS)
libgs_plugin_packagekit_refine_la_LDFLAGS = -module -avoid-version
libgs_plugin_packagekit_refine_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARNINGFLAGS_C)
+libgs_plugin_packagekit_search_la_SOURCES = \
+ gs-plugin-packagekit-search.c \
+ packagekit-common.c \
+ packagekit-common.h
+libgs_plugin_packagekit_search_la_LIBADD = $(GS_PLUGIN_LIBS) $(PACKAGEKIT_LIBS)
+libgs_plugin_packagekit_search_la_LDFLAGS = -module -avoid-version
+libgs_plugin_packagekit_search_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARNINGFLAGS_C)
+
libgs_plugin_packagekit_updates_la_SOURCES = \
gs-plugin-packagekit-updates.c \
packagekit-common.c \
diff --git a/src/plugins/gs-plugin-packagekit-search.c b/src/plugins/gs-plugin-packagekit-search.c
new file mode 100644
index 0000000..3cd93b0
--- /dev/null
+++ b/src/plugins/gs-plugin-packagekit-search.c
@@ -0,0 +1,157 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2013 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <config.h>
+
+#define I_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE
+#include <packagekit-glib2/packagekit.h>
+#include <glib/gi18n.h>
+
+#include <gs-plugin.h>
+
+#include "packagekit-common.h"
+
+struct GsPluginPrivate {
+ PkClient *client;
+};
+
+/**
+ * gs_plugin_get_name:
+ */
+const gchar *
+gs_plugin_get_name (void)
+{
+ return "packagekit-search";
+}
+
+/**
+ * gs_plugin_initialize:
+ */
+void
+gs_plugin_initialize (GsPlugin *plugin)
+{
+ /* create private area */
+ plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
+ plugin->priv->client = pk_client_new ();
+ pk_client_set_background (plugin->priv->client, FALSE);
+ pk_client_set_interactive (plugin->priv->client, FALSE);
+ pk_client_set_cache_age (plugin->priv->client, G_MAXUINT);
+
+ /* at the moment we don't need this; or at least I can't think of
+ * a reason *right now* :) */
+ gs_plugin_set_enabled (plugin, FALSE);
+}
+
+/**
+ * gs_plugin_get_priority:
+ */
+gdouble
+gs_plugin_get_priority (GsPlugin *plugin)
+{
+ return 10.0f;
+}
+
+/**
+ * gs_plugin_destroy:
+ */
+void
+gs_plugin_destroy (GsPlugin *plugin)
+{
+ g_object_unref (plugin->priv->client);
+}
+
+/**
+ * gs_plugin_packagekit_progress_cb:
+ **/
+static void
+gs_plugin_packagekit_progress_cb (PkProgress *progress,
+ PkProgressType type,
+ gpointer user_data)
+{
+ GsPluginStatus plugin_status;
+ PkStatusEnum status;
+ GsPlugin *plugin = GS_PLUGIN (user_data);
+
+ if (type != PK_PROGRESS_TYPE_STATUS)
+ return;
+ g_object_get (progress,
+ "status", &status,
+ NULL);
+
+ /* profile */
+ if (status == PK_STATUS_ENUM_SETUP) {
+ gs_profile_start_full (plugin->profile,
+ "packagekit-search::transaction");
+ } else if (status == PK_STATUS_ENUM_FINISHED) {
+ gs_profile_stop_full (plugin->profile,
+ "packagekit-search::transaction");
+ }
+
+ plugin_status = packagekit_status_enum_to_plugin_status (status);
+ if (plugin_status != GS_PLUGIN_STATUS_UNKNOWN)
+ gs_plugin_status_update (plugin, NULL, plugin_status);
+}
+
+/**
+ * gs_plugin_add_search:
+ */
+gboolean
+gs_plugin_add_search (GsPlugin *plugin,
+ const gchar *value,
+ GList **list,
+ GCancellable *cancellable,
+ GError **error)
+{
+ const gchar *values[2] = { NULL, NULL };
+ gboolean ret = TRUE;
+ PkBitfield filter;
+ PkResults *results;
+
+ /* update UI as this might take some time */
+ gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
+
+ /* do sync call */
+ filter = pk_bitfield_from_enums (PK_FILTER_ENUM_NEWEST,
+ PK_FILTER_ENUM_ARCH,
+ PK_FILTER_ENUM_APPLICATION,
+ PK_FILTER_ENUM_NOT_COLLECTIONS,
+ -1);
+ values[0] = value;
+ results = pk_client_search_details (plugin->priv->client,
+ filter,
+ (gchar **) values,
+ cancellable,
+ gs_plugin_packagekit_progress_cb, plugin,
+ error);
+ if (results == NULL) {
+ ret = FALSE;
+ goto out;
+ }
+
+ /* add results */
+ ret = gs_plugin_packagekit_add_results (plugin, list, results, error);
+ if (!ret)
+ goto out;
+out:
+ if (results != NULL)
+ g_object_unref (results);
+ return ret;
+}
diff --git a/src/plugins/gs-plugin-packagekit.c b/src/plugins/gs-plugin-packagekit.c
index e7b4a86..b8e77b0 100644
--- a/src/plugins/gs-plugin-packagekit.c
+++ b/src/plugins/gs-plugin-packagekit.c
@@ -107,155 +107,6 @@ gs_plugin_packagekit_progress_cb (PkProgress *progress,
}
/**
- * gs_plugin_packagekit_add_installed_results:
- */
-static gboolean
-gs_plugin_packagekit_add_installed_results (GsPlugin *plugin,
- GList **list,
- PkResults *results,
- GError **error)
-{
- const gchar *package_id;
- gboolean ret = TRUE;
- GHashTable *installed = NULL;
- GPtrArray *array = NULL;
- GPtrArray *array_filtered = NULL;
- GsApp *app;
- guint i;
- PkError *error_code = NULL;
- PkPackage *package;
-
- /* check error code */
- error_code = pk_results_get_error_code (results);
- if (error_code != NULL) {
- ret = FALSE;
- g_set_error (error,
- GS_PLUGIN_ERROR,
- GS_PLUGIN_ERROR_FAILED,
- "failed to get-packages: %s, %s",
- pk_error_enum_to_string (pk_error_get_code (error_code)),
- pk_error_get_details (error_code));
- goto out;
- }
-
- /* add all installed packages to a hash */
- installed = g_hash_table_new (g_str_hash, g_str_equal);
- array = pk_results_get_package_array (results);
- for (i = 0; i < array->len; i++) {
- package = g_ptr_array_index (array, i);
- if (pk_package_get_info (package) != PK_INFO_ENUM_INSTALLED)
- continue;
- g_hash_table_insert (installed,
- (const gpointer) pk_package_get_name (package),
- (const gpointer) pk_package_get_id (package));
- }
-
- /* if the search returns more than one package with the same name,
- * ignore everything with that name except the installed package */
- array_filtered = g_ptr_array_new ();
- for (i = 0; i < array->len; i++) {
- package = g_ptr_array_index (array, i);
- package_id = g_hash_table_lookup (installed, pk_package_get_name (package));
- if (pk_package_get_info (package) == PK_INFO_ENUM_INSTALLED || package_id == NULL) {
- g_ptr_array_add (array_filtered, package);
- } else {
- g_debug ("ignoring available %s as installed %s also reported",
- pk_package_get_id (package), package_id);
- }
- }
-
- /* process packages */
- for (i = 0; i < array_filtered->len; i++) {
- package = g_ptr_array_index (array_filtered, i);
-
- app = gs_app_new (NULL);
- gs_app_set_metadata (app,
- "PackageKit::package-id",
- pk_package_get_id (package));
- gs_app_set_metadata (app,
- "PackageKit::package-summary",
- pk_package_get_summary (package));
- gs_app_set_source (app, pk_package_get_name (package));
- gs_app_set_management_plugin (app, "PackageKit");
- gs_app_set_version (app, pk_package_get_version (package));
- switch (pk_package_get_info (package)) {
- case PK_INFO_ENUM_INSTALLED:
- gs_app_set_state (app, GS_APP_STATE_INSTALLED);
- break;
- case PK_INFO_ENUM_AVAILABLE:
- gs_app_set_state (app, GS_APP_STATE_AVAILABLE);
- break;
- default:
- gs_app_set_state (app, GS_APP_STATE_UNKNOWN);
- g_warning ("unknown info state of %s",
- pk_info_enum_to_string (pk_package_get_info (package)));
- }
- gs_app_set_kind (app, GS_APP_KIND_PACKAGE);
- gs_plugin_add_app (list, app);
- g_object_unref (app);
- }
-out:
- if (installed != NULL)
- g_hash_table_unref (installed);
- if (error_code != NULL)
- g_object_unref (error_code);
- if (array != NULL)
- g_ptr_array_unref (array);
- if (array_filtered != NULL)
- g_ptr_array_unref (array_filtered);
- return ret;
-}
-
-/**
- * gs_plugin_add_search:
- */
-gboolean
-gs_plugin_add_search (GsPlugin *plugin,
- const gchar *value,
- GList **list,
- GCancellable *cancellable,
- GError **error)
-{
- const gchar *values[2] = { NULL, NULL };
- gboolean ret = TRUE;
- PkBitfield filter;
- PkResults *results;
-
- /* update UI as this might take some time */
- gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
-
- /* do sync call */
- filter = pk_bitfield_from_enums (PK_FILTER_ENUM_NEWEST,
- PK_FILTER_ENUM_ARCH,
- PK_FILTER_ENUM_APPLICATION,
- PK_FILTER_ENUM_NOT_COLLECTIONS,
- -1);
- values[0] = value;
- results = pk_client_search_details (PK_CLIENT(plugin->priv->task),
- filter,
- (gchar **) values,
- cancellable,
- gs_plugin_packagekit_progress_cb, plugin,
- error);
- if (results == NULL) {
- ret = FALSE;
- goto out;
- }
-
- /* add results */
- ret = gs_plugin_packagekit_add_installed_results (plugin,
- list,
- results,
- error);
- if (!ret)
- goto out;
-out:
- if (results != NULL)
- g_object_unref (results);
- return ret;
-}
-
-/**
* gs_plugin_add_installed:
*/
gboolean
@@ -289,10 +140,7 @@ gs_plugin_add_installed (GsPlugin *plugin,
}
/* add results */
- ret = gs_plugin_packagekit_add_installed_results (plugin,
- list,
- results,
- error);
+ ret = gs_plugin_packagekit_add_results (plugin, list, results, error);
if (!ret)
goto out;
out:
diff --git a/src/plugins/packagekit-common.c b/src/plugins/packagekit-common.c
index 53f6d1b..2863781 100644
--- a/src/plugins/packagekit-common.c
+++ b/src/plugins/packagekit-common.c
@@ -21,6 +21,10 @@
#include "config.h"
+#define I_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE
+#include <packagekit-glib2/packagekit.h>
+#include <gs-plugin.h>
+
#include "packagekit-common.h"
/**
@@ -76,3 +80,103 @@ packagekit_status_enum_to_plugin_status (PkStatusEnum status)
}
return plugin_status;
}
+
+/**
+ * gs_plugin_packagekit_add_results:
+ */
+gboolean
+gs_plugin_packagekit_add_results (GsPlugin *plugin,
+ GList **list,
+ PkResults *results,
+ GError **error)
+{
+ const gchar *package_id;
+ gboolean ret = TRUE;
+ GHashTable *installed = NULL;
+ GPtrArray *array = NULL;
+ GPtrArray *array_filtered = NULL;
+ GsApp *app;
+ guint i;
+ PkError *error_code = NULL;
+ PkPackage *package;
+
+ /* check error code */
+ error_code = pk_results_get_error_code (results);
+ if (error_code != NULL) {
+ ret = FALSE;
+ g_set_error (error,
+ GS_PLUGIN_ERROR,
+ GS_PLUGIN_ERROR_FAILED,
+ "failed to get-packages: %s, %s",
+ pk_error_enum_to_string (pk_error_get_code (error_code)),
+ pk_error_get_details (error_code));
+ goto out;
+ }
+
+ /* add all installed packages to a hash */
+ installed = g_hash_table_new (g_str_hash, g_str_equal);
+ array = pk_results_get_package_array (results);
+ for (i = 0; i < array->len; i++) {
+ package = g_ptr_array_index (array, i);
+ if (pk_package_get_info (package) != PK_INFO_ENUM_INSTALLED)
+ continue;
+ g_hash_table_insert (installed,
+ (const gpointer) pk_package_get_name (package),
+ (const gpointer) pk_package_get_id (package));
+ }
+
+ /* if the search returns more than one package with the same name,
+ * ignore everything with that name except the installed package */
+ array_filtered = g_ptr_array_new ();
+ for (i = 0; i < array->len; i++) {
+ package = g_ptr_array_index (array, i);
+ package_id = g_hash_table_lookup (installed, pk_package_get_name (package));
+ if (pk_package_get_info (package) == PK_INFO_ENUM_INSTALLED || package_id == NULL) {
+ g_ptr_array_add (array_filtered, package);
+ } else {
+ g_debug ("ignoring available %s as installed %s also reported",
+ pk_package_get_id (package), package_id);
+ }
+ }
+
+ /* process packages */
+ for (i = 0; i < array_filtered->len; i++) {
+ package = g_ptr_array_index (array_filtered, i);
+
+ app = gs_app_new (NULL);
+ gs_app_set_metadata (app,
+ "PackageKit::package-id",
+ pk_package_get_id (package));
+ gs_app_set_metadata (app,
+ "PackageKit::package-summary",
+ pk_package_get_summary (package));
+ gs_app_set_source (app, pk_package_get_name (package));
+ gs_app_set_management_plugin (app, "PackageKit");
+ gs_app_set_version (app, pk_package_get_version (package));
+ switch (pk_package_get_info (package)) {
+ case PK_INFO_ENUM_INSTALLED:
+ gs_app_set_state (app, GS_APP_STATE_INSTALLED);
+ break;
+ case PK_INFO_ENUM_AVAILABLE:
+ gs_app_set_state (app, GS_APP_STATE_AVAILABLE);
+ break;
+ default:
+ gs_app_set_state (app, GS_APP_STATE_UNKNOWN);
+ g_warning ("unknown info state of %s",
+ pk_info_enum_to_string (pk_package_get_info (package)));
+ }
+ gs_app_set_kind (app, GS_APP_KIND_PACKAGE);
+ gs_plugin_add_app (list, app);
+ g_object_unref (app);
+ }
+out:
+ if (installed != NULL)
+ g_hash_table_unref (installed);
+ if (error_code != NULL)
+ g_object_unref (error_code);
+ if (array != NULL)
+ g_ptr_array_unref (array);
+ if (array_filtered != NULL)
+ g_ptr_array_unref (array_filtered);
+ return ret;
+}
diff --git a/src/plugins/packagekit-common.h b/src/plugins/packagekit-common.h
index e553ac8..c99390b 100644
--- a/src/plugins/packagekit-common.h
+++ b/src/plugins/packagekit-common.h
@@ -32,6 +32,11 @@ G_BEGIN_DECLS
GsPluginStatus packagekit_status_enum_to_plugin_status (PkStatusEnum status);
+gboolean gs_plugin_packagekit_add_results (GsPlugin *plugin,
+ GList **list,
+ PkResults *results,
+ GError **error);
+
G_END_DECLS
#endif /* __APPSTREAM_CACHE_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]