[gnome-software: 7/10] fedora-pkgdb-collections: Split JSON parsing out into a helper
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 7/10] fedora-pkgdb-collections: Split JSON parsing out into a helper
- Date: Tue, 22 Feb 2022 12:47:58 +0000 (UTC)
commit 17e45a0cb5c17062b52bea8392217db1e5e56601
Author: Philip Withnall <pwithnall endlessos org>
Date: Fri Feb 11 16:45:55 2022 +0000
fedora-pkgdb-collections: Split JSON parsing out into a helper
It has quite complex control flow, so if `_ensure_cache()` is to be
made asynchronous, that will require a lot of `g_task_return_boolean()`
branches.
Easier to split it out into a helper function and call that, given that
the parsing is synchronous.
This will help with future refactoring.
This introduces no functional changes.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Helps: #1472
.../gs-plugin-fedora-pkgdb-collections.c | 31 +++++++++++++---------
1 file changed, 19 insertions(+), 12 deletions(-)
---
diff --git a/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
b/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
index 7cd799d58..41b1f0d80 100644
--- a/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
+++ b/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
@@ -403,9 +403,8 @@ _is_valid_upgrade (GsPluginFedoraPkgdbCollections *self,
}
static gboolean
-_ensure_cache (GsPluginFedoraPkgdbCollections *self,
- GCancellable *cancellable,
- GError **error)
+load_json (GsPluginFedoraPkgdbCollections *self,
+ GError **error)
{
JsonArray *collections;
JsonObject *root;
@@ -415,15 +414,6 @@ _ensure_cache (GsPluginFedoraPkgdbCollections *self,
#endif /* json-glib < 1.6.0 */
g_autoptr(JsonParser) parser = NULL;
- /* already done */
- if (self->is_valid)
- return TRUE;
-
- /* just ensure there is any data, no matter how old */
- /* FIXME: This can download from the network, so needs to be made async */
- if (!_refresh_cache (self, G_MAXUINT, cancellable, error))
- return FALSE;
-
#if JSON_CHECK_VERSION(1, 6, 0)
parser = json_parser_new_immutable ();
if (!json_parser_load_from_mapped_file (parser, self->cachefn, error))
@@ -515,6 +505,23 @@ _ensure_cache (GsPluginFedoraPkgdbCollections *self,
return TRUE;
}
+static gboolean
+_ensure_cache (GsPluginFedoraPkgdbCollections *self,
+ GCancellable *cancellable,
+ GError **error)
+{
+ /* already done */
+ if (self->is_valid)
+ return TRUE;
+
+ /* just ensure there is any data, no matter how old */
+ /* FIXME: This can download from the network, so needs to be made async */
+ if (!_refresh_cache (self, G_MAXUINT, cancellable, error))
+ return FALSE;
+
+ return load_json (self, error);
+}
+
static PkgdbItem *
_get_item_by_cpe_name (GsPluginFedoraPkgdbCollections *self,
const gchar *cpe_name)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]