summaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2010-03-10 11:31:28 +0000
committerRichard Hughes <richard@hughsie.com>2010-03-10 13:51:57 +0000
commit4484f491f41ac0269cc8d4cc8a56d3e5a6e279f8 (patch)
tree852babaa8f0d5362bac8167eb2701181ba64b3be /backends
parentbcbb8b4264f19a601d48347f3a6341054308ce01 (diff)
yum: for installed packages, use Zif to get the package details
This is 2.1x faster than using yum
Diffstat (limited to 'backends')
-rw-r--r--backends/yum/libzif/zif-package-local.c11
-rw-r--r--backends/yum/libzif/zif-package.c4
-rw-r--r--backends/yum/libzif/zif-package.h1
-rw-r--r--backends/yum/pk-backend-yum.c143
4 files changed, 136 insertions, 23 deletions
diff --git a/backends/yum/libzif/zif-package-local.c b/backends/yum/libzif/zif-package-local.c
index 5d57cde56..e04f8d911 100644
--- a/backends/yum/libzif/zif-package-local.c
+++ b/backends/yum/libzif/zif-package-local.c
@@ -359,10 +359,17 @@ zif_package_local_ensure_data (ZifPackage *pkg, ZifPackageEnsureType type, GErro
if (size != 0)
zif_package_set_size (pkg, size);
- } else if (type == ZIF_PACKAGE_ENSURE_TYPE_GROUP) {
- /* category && group */
+ } else if (type == ZIF_PACKAGE_ENSURE_TYPE_CATEGORY) {
+ /* category */
tmp = zif_get_header_string (header, RPMTAG_GROUP);
zif_package_set_category (pkg, tmp);
+ zif_string_unref (tmp);
+
+ } else if (type == ZIF_PACKAGE_ENSURE_TYPE_GROUP) {
+ /* group */
+ tmp = zif_package_get_category (pkg, error);
+ if (tmp == NULL)
+ goto out;
group = zif_groups_get_group_for_cat (ZIF_PACKAGE_LOCAL (pkg)->priv->groups, zif_string_get_value (tmp), NULL);
if (group != PK_GROUP_ENUM_UNKNOWN)
zif_package_set_group (pkg, group);
diff --git a/backends/yum/libzif/zif-package.c b/backends/yum/libzif/zif-package.c
index 9fa874c03..4336e62d8 100644
--- a/backends/yum/libzif/zif-package.c
+++ b/backends/yum/libzif/zif-package.c
@@ -704,7 +704,7 @@ zif_package_get_category (ZifPackage *package, GError **error)
/* not exists */
if (package->priv->category == NULL) {
- ret = zif_package_ensure_data (package, ZIF_PACKAGE_ENSURE_TYPE_GROUP, error);
+ ret = zif_package_ensure_data (package, ZIF_PACKAGE_ENSURE_TYPE_CATEGORY, error);
if (!ret)
return NULL;
}
@@ -729,7 +729,7 @@ zif_package_get_group (ZifPackage *package, GError **error)
/* not exists */
if (package->priv->group == PK_GROUP_ENUM_UNKNOWN) {
- ret = zif_package_ensure_data (package, ZIF_PACKAGE_ENSURE_TYPE_FILES, error);
+ ret = zif_package_ensure_data (package, ZIF_PACKAGE_ENSURE_TYPE_GROUP, error);
if (!ret)
return PK_GROUP_ENUM_UNKNOWN;
}
diff --git a/backends/yum/libzif/zif-package.h b/backends/yum/libzif/zif-package.h
index d66c5b911..bbb4feae1 100644
--- a/backends/yum/libzif/zif-package.h
+++ b/backends/yum/libzif/zif-package.h
@@ -54,6 +54,7 @@ typedef enum {
ZIF_PACKAGE_ENSURE_TYPE_URL,
ZIF_PACKAGE_ENSURE_TYPE_SIZE,
ZIF_PACKAGE_ENSURE_TYPE_GROUP,
+ ZIF_PACKAGE_ENSURE_TYPE_CATEGORY,
ZIF_PACKAGE_ENSURE_TYPE_REQUIRES,
ZIF_PACKAGE_ENSURE_TYPE_PROVIDES,
ZIF_PACKAGE_ENSURE_TYPE_CONFLICTS,
diff --git a/backends/yum/pk-backend-yum.c b/backends/yum/pk-backend-yum.c
index 0bd421745..c4b06d483 100644
--- a/backends/yum/pk-backend-yum.c
+++ b/backends/yum/pk-backend-yum.c
@@ -171,6 +171,25 @@ backend_get_lock (PkBackend *backend)
}
/**
+ * backend_is_all_installed:
+ */
+static gboolean
+backend_is_all_installed (gchar **package_ids)
+{
+ guint i;
+ gboolean ret = TRUE;
+
+ /* check if we can use zif */
+ for (i=0; package_ids[i] != NULL; i++) {
+ if (!g_str_has_suffix (package_ids[i], ";installed")) {
+ ret = FALSE;
+ break;
+ }
+ }
+ return ret;
+}
+
+/**
* backend_unlock:
*/
static gboolean
@@ -462,6 +481,102 @@ backend_get_depends (PkBackend *backend, PkBitfield filters, gchar **package_ids
g_free (package_ids_temp);
}
+
+/**
+ * backend_get_details_thread:
+ */
+static gboolean
+backend_get_details_thread (PkBackend *backend)
+{
+ gboolean ret;
+ gchar **package_ids = pk_backend_get_strv (backend, "package_ids");
+ GPtrArray *store_array = NULL;
+ ZifPackage *package;
+ ZifCompletion *completion_local;
+ const gchar *id;
+ guint i;
+ guint len;
+ GError *error = NULL;
+ ZifString *license;
+ ZifString *description;
+ ZifString *url;
+ PkGroupEnum group;
+ guint64 size;
+
+ /* get lock */
+ ret = backend_get_lock (backend);
+ if (!ret) {
+ egg_warning ("failed to get lock");
+ goto out;
+ }
+
+ /* set the network state */
+ backend_setup_network (backend);
+
+ len = g_strv_length (package_ids);
+
+ /* setup completion */
+ zif_completion_reset (priv->completion);
+ zif_completion_set_number_steps (priv->completion, len + 1);
+
+ /* find all the packages */
+ completion_local = zif_completion_get_child (priv->completion);
+// store_array = backend_get_default_store_array_for_filter (backend, PK_FILTER_ENUM_UNKNOWN, completion_local);
+{
+ ZifStore *store;
+ store = ZIF_STORE (zif_store_local_new ());
+ store_array = zif_store_array_new ();
+ zif_store_array_add_store (store_array, store);
+ g_object_unref (store);
+}
+
+ /* this section done */
+ zif_completion_done (priv->completion);
+
+ pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
+ for (i=0; package_ids[i] != NULL; i++) {
+ id = package_ids[i];
+ completion_local = zif_completion_get_child (priv->completion);
+ package = zif_store_array_find_package (store_array, id, priv->cancellable, completion_local, &error);
+ if (package == NULL) {
+ pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "failed to find %s: %s", package_ids[i], error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ /* get data */
+ license = zif_package_get_license (package, NULL);
+ group = zif_package_get_group (package, NULL);
+ description = zif_package_get_description (package, NULL);
+ url = zif_package_get_url (package, NULL);
+ size = zif_package_get_size (package, NULL);
+
+ /* emit */
+ pk_backend_details (backend,
+ package_ids[i],
+ zif_string_get_value (license),
+ group,
+ zif_string_get_value (description),
+ zif_string_get_value (url),
+ (gulong) size);
+
+ /* this section done */
+ zif_completion_done (priv->completion);
+
+ /* free */
+ zif_string_unref (license);
+ zif_string_unref (description);
+ zif_string_unref (url);
+ g_object_unref (package);
+ }
+out:
+ backend_unlock (backend);
+ pk_backend_finished (backend);
+ if (store_array != NULL)
+ g_ptr_array_unref (store_array);
+ return TRUE;
+}
+
/**
* backend_get_details:
*/
@@ -469,6 +584,15 @@ static void
backend_get_details (PkBackend *backend, gchar **package_ids)
{
gchar *package_ids_temp;
+ gboolean ret;
+
+ /* check if we can use zif */
+ ret = backend_is_all_installed (package_ids);
+ if (ret) {
+ pk_backend_thread_create (backend, backend_get_details_thread);
+ return;
+ }
+
package_ids_temp = pk_package_ids_to_string (package_ids);
pk_backend_spawn_helper (priv->spawn, "yumBackend.py", "get-details", package_ids_temp, NULL);
g_free (package_ids_temp);
@@ -696,25 +820,6 @@ out:
}
/**
- * backend_is_all_installed:
- */
-static gboolean
-backend_is_all_installed (gchar **package_ids)
-{
- guint i;
- gboolean ret = TRUE;
-
- /* check if we can use zif */
- for (i=0; package_ids[i] != NULL; i++) {
- if (!g_str_has_suffix (package_ids[i], ";installed")) {
- ret = FALSE;
- break;
- }
- }
- return ret;
-}
-
-/**
* backend_get_files:
*/
static void