[libgweather/benzea/wip-variant-backend: 2/4] Only get nearest child when first needed
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgweather/benzea/wip-variant-backend: 2/4] Only get nearest child when first needed
- Date: Sun, 26 Apr 2020 17:29:00 +0000 (UTC)
commit b24c865f1ad704aa4bf704856e6993d6cb99ee6a
Author: Benjamin Berg <bberg redhat com>
Date: Sun Apr 26 19:27:38 2020 +0200
Only get nearest child when first needed
libgweather/gweather-location.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
---
diff --git a/libgweather/gweather-location.c b/libgweather/gweather-location.c
index 62b5207..f677426 100644
--- a/libgweather/gweather-location.c
+++ b/libgweather/gweather-location.c
@@ -258,13 +258,6 @@ location_ref_for_idx (GWeatherDb *db,
loc->forecast_zone = g_strdup (EMPTY_TO_NULL (db_location_get_forecast_zone (ref)));
loc->radar = g_strdup (EMPTY_TO_NULL (db_location_get_radar (ref)));
- /* Fill in the magic nearest child if we need to and should. */
- if (!g_getenv ("LIBGWEATHER_LOCATIONS_NO_NEAREST") &&
- IDX_VALID (db_location_get_nearest (ref))) {
- loc->_children = g_new0 (GWeatherLocation*, 2);
- loc->_children[0] = location_ref_for_idx (db, db_location_get_nearest (ref), loc);
- }
-
/* Note, we used to sort locations by distance (for cities) and name;
* Distance sorting is done in the variant already,
* name sorting however needs translations and is not done anymore. */
@@ -747,6 +740,17 @@ gweather_location_get_children (GWeatherLocation *loc)
if (!loc->db)
return &no_children;
+ /* Fill in the magic nearest child if we need to and should.
+ * NOTE: This reference is weak and automatically free'ed! */
+ if (!g_getenv ("LIBGWEATHER_LOCATIONS_NO_NEAREST") &&
+ IDX_VALID (db_location_get_nearest (loc->ref))) {
+ loc->_children = g_new0 (GWeatherLocation*, 2);
+ loc->_children[0] = location_ref_for_idx (loc->db, db_location_get_nearest (loc->ref), loc);
+
+ return loc->_children;
+ }
+
+ /* Get the actual children. */
children_ref = db_location_get_children (loc->ref);
length = db_arrayofuint16_get_length (children_ref);
if (length == 0)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]