[gnome-software] odrs: Do not assume the moderatable results are ordered
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] odrs: Do not assume the moderatable results are ordered
- Date: Sun, 17 Apr 2016 19:06:35 +0000 (UTC)
commit 5f75573ca538d6cc80d36b5cabe3e125818bb266
Author: Richard Hughes <richard hughsie com>
Date: Sun Apr 17 20:04:55 2016 +0100
odrs: Do not assume the moderatable results are ordered
src/plugins/gs-plugin-odrs.c | 19 ++++++++++---------
1 files changed, 10 insertions(+), 9 deletions(-)
---
diff --git a/src/plugins/gs-plugin-odrs.c b/src/plugins/gs-plugin-odrs.c
index f58bb96..28f3d22 100644
--- a/src/plugins/gs-plugin-odrs.c
+++ b/src/plugins/gs-plugin-odrs.c
@@ -950,13 +950,11 @@ gs_plugin_add_unvoted_reviews (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
- const gchar *app_id_last = NULL;
guint status_code;
guint i;
g_autofree gchar *uri = NULL;
- g_autoptr(GFile) cachefn_file = NULL;
+ g_autoptr(GHashTable) hash = NULL;
g_autoptr(GPtrArray) reviews = NULL;
- g_autoptr(GsApp) app_current = NULL;
g_autoptr(SoupMessage) msg = NULL;
/* create the GET data *with* the machine hash so we can later
@@ -986,20 +984,23 @@ gs_plugin_add_unvoted_reviews (GsPlugin *plugin,
return FALSE;
/* look at all the reviews; faking application objects */
+ hash = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, (GDestroyNotify) g_object_unref);
for (i = 0; i < reviews->len; i++) {
+ GsApp *app;
GsReview *review;
const gchar *app_id;
/* same app? */
review = g_ptr_array_index (reviews, i);
app_id = gs_review_get_metadata_item (review, "app_id");
- if (g_strcmp0 (app_id, app_id_last) != 0) {
- g_clear_object (&app_current);
- app_current = gs_plugin_create_app_dummy (app_id);
- gs_plugin_add_app (list, app_current);
- app_id_last = app_id;
+ app = g_hash_table_lookup (hash, app_id);
+ if (app == NULL) {
+ app = gs_plugin_create_app_dummy (app_id);
+ gs_plugin_add_app (list, app);
+ g_hash_table_insert (hash, g_strdup (app_id), app);
}
- gs_app_add_review (app_current, review);
+ gs_app_add_review (app, review);
}
return TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]