Commit 38c2aa1a authored by Sam Thursfield's avatar Sam Thursfield

photos-tracker-queue: Keep object alive when init fails

If init succeeds, we will have one singleton as before.
If init fails, we will also have one singleton, which will
return an error any time g_initable_init() is called
(thanks to 51b22906).

Previously, if init failed, the weak reference would cause the `static
GObject *self` value inside the constructor function to return to NULL,
meaning the next call to photos_tracker_queue_dup_singleton() would try
to initialise Tracker again. In some cases this could result in a very
slow startup.
parent d85b07c0
Pipeline #198492 passed with stage
in 14 minutes and 14 seconds
......@@ -70,7 +70,7 @@ photos_search_context_state_free (PhotosSearchContextState *state)
g_object_unref (state->srch_mtch_mngr);
g_object_unref (state->srch_typ_mngr);
g_object_unref (state->srch_cntrlr);
g_object_unref (state->queue);
g_clear_object (&state->queue);
g_slice_free (PhotosSearchContextState, state);
}
......
......@@ -292,6 +292,12 @@ photos_tracker_controller_perform_current_query (PhotosTrackerController *self)
priv = photos_tracker_controller_get_instance_private (self);
if (G_UNLIKELY (priv->queue == NULL))
{
photos_tracker_controller_query_error (self, priv->queue_error);
goto out;
}
g_clear_object (&priv->current_query);
priv->current_query = PHOTOS_TRACKER_CONTROLLER_GET_CLASS (self)->get_query (self);
g_return_if_fail (priv->current_query != NULL);
......@@ -303,12 +309,6 @@ photos_tracker_controller_perform_current_query (PhotosTrackerController *self)
g_object_unref (priv->cancellable);
priv->cancellable = g_cancellable_new ();
if (G_UNLIKELY (priv->queue == NULL))
{
photos_tracker_controller_query_error (self, priv->queue_error);
goto out;
}
photos_tracker_queue_select (priv->queue,
priv->current_query,
priv->cancellable,
......
......@@ -444,6 +444,7 @@ photos_tracker_queue_initable_init (GInitable *initable, GCancellable *cancellab
else
{
photos_debug (PHOTOS_DEBUG_TRACKER, "Initialization failed due to %s", self->initialization_error->message);
g_clear_object (&self->connection);
ret_val = FALSE;
}
......@@ -470,10 +471,20 @@ photos_tracker_queue_initable_iface_init (GInitableIface *iface)
PhotosTrackerQueue *
photos_tracker_queue_dup_singleton (GCancellable *cancellable, GError **error)
{
GObject *singleton;
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
return g_initable_new (PHOTOS_TYPE_TRACKER_QUEUE, cancellable, error, NULL);
singleton = g_object_new (PHOTOS_TYPE_TRACKER_QUEUE, NULL);
if (g_initable_init (G_INITABLE (singleton), cancellable, error))
return PHOTOS_TRACKER_QUEUE (singleton);
/* On error we deliberately don't unref the object so that we won't try
* and re-initialize Tracker when called again.
*/
return NULL;
}
const gchar *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment