[tracker/wip/carlosg/tracker-3.0-api-breaks: 42/100] libtracker-sparql: Drop GError array return value in update_array()
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/tracker-3.0-api-breaks: 42/100] libtracker-sparql: Drop GError array return value in update_array()
- Date: Mon, 17 Feb 2020 18:12:20 +0000 (UTC)
commit f06d078094355af47b58bcbfa13161d76b638d10
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Dec 28 01:53:54 2019 +0100
libtracker-sparql: Drop GError array return value in update_array()
If tracker_sparql_connection_update_array() fails, it will try each
individual update separately, and return a GError for each of them.
This behavior is 100% anti-ACID, and a pain to handle. Instead, have
update_array() handle everything in a single transaction, and return
a single error for all of it, if any.
.../reference/libtracker-sparql/migrating-2to3.xml | 8 ++++++
src/libtracker-bus/tracker-bus.vala | 23 ++--------------
src/libtracker-direct/tracker-direct.c | 32 +++++-----------------
src/libtracker-sparql-backend/tracker-backend.vala | 2 +-
src/libtracker-sparql/tracker-connection.vala | 16 +++--------
tests/tracker-steroids/tracker-test.c | 16 ++---------
6 files changed, 24 insertions(+), 73 deletions(-)
---
diff --git a/docs/reference/libtracker-sparql/migrating-2to3.xml
b/docs/reference/libtracker-sparql/migrating-2to3.xml
index f54b1cbd7..afd3f132b 100644
--- a/docs/reference/libtracker-sparql/migrating-2to3.xml
+++ b/docs/reference/libtracker-sparql/migrating-2to3.xml
@@ -142,4 +142,12 @@ ORDER BY DESC ?count
apply to.
</para>
</section>
+ <section>
+ <title>Return value change in tracker_sparql_connection_update_array()</title>
+ <para>
+ This function changed to handle all changes within a single transaction. Returning
+ an array of errors for each individual update is no longer necessary, so it now
+ simply returns a boolean return value.
+ </para>
+ </section>
</chapter>
diff --git a/src/libtracker-bus/tracker-bus.vala b/src/libtracker-bus/tracker-bus.vala
index 56bfae113..25871335f 100644
--- a/src/libtracker-bus/tracker-bus.vala
+++ b/src/libtracker-bus/tracker-bus.vala
@@ -177,7 +177,7 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
handle_error_reply (reply);
}
- public async override GenericArray<Sparql.Error?>? update_array_async (string[] sparql, int priority
= GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, GLib.Error, GLib.IOError,
DBusError {
+ public async override bool update_array_async (string[] sparql, int priority = GLib.Priority.DEFAULT,
Cancellable? cancellable = null) throws Sparql.Error, GLib.Error, GLib.IOError, DBusError {
UnixInputStream input;
UnixOutputStream output;
pipe (out input, out output);
@@ -211,26 +211,7 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
var reply = bus.send_message_with_reply.end (dbus_res);
handle_error_reply (reply);
- // process results (errors)
- var result = new GenericArray<Sparql.Error?> ();
- Variant resultv;
- resultv = reply.get_body ().get_child_value (0);
- var iter = resultv.iterator ();
- string code, message;
- while (iter.next ("s", out code)) {
- if (iter.next ("s", out message)) {
- if (code != "" && message != "") {
- result.add (new Sparql.Error.INTERNAL (message));
- } else {
- result.add (null);
- }
-
- message = null;
- }
-
- code = null;
- }
- return result;
+ return true;
}
public override GLib.Variant? update_blank (string sparql, int priority = GLib.Priority.DEFAULT,
Cancellable? cancellable = null) throws Sparql.Error, GLib.Error, GLib.IOError, DBusError {
diff --git a/src/libtracker-direct/tracker-direct.c b/src/libtracker-direct/tracker-direct.c
index 9bf4dad86..4991e1a52 100644
--- a/src/libtracker-direct/tracker-direct.c
+++ b/src/libtracker-direct/tracker-direct.c
@@ -734,39 +734,21 @@ update_array_async_thread_func (GTask *task,
gchar *concatenated;
GPtrArray *errors;
GError *error = NULL;
- gint i;
errors = g_ptr_array_new_with_free_func ((GDestroyNotify) error_free);
g_ptr_array_set_size (errors, g_strv_length (updates));
- /* Fast path, perform everything as a single update */
- concatenated = g_strjoinv ("; ", updates);
+ concatenated = g_strjoinv ("\n", updates);
tracker_sparql_connection_update (source_object, concatenated,
g_task_get_priority (task),
cancellable, &error);
g_free (concatenated);
- if (!error) {
- g_task_return_pointer (task, errors,
- (GDestroyNotify) g_ptr_array_unref);
- g_object_unref (task);
- return;
- }
-
- g_error_free (error);
-
- /* Slow path, perform updates one by one */
- for (i = 0; updates[i]; i++) {
- GError **err = NULL;
-
- err = (GError **) &g_ptr_array_index (errors, i);
- tracker_sparql_connection_update (source_object, updates[i],
- g_task_get_priority (task),
- cancellable, err);
- }
+ if (error)
+ g_task_return_error (task, error);
+ else
+ g_task_return_boolean (task, TRUE);
- g_task_return_pointer (task, errors,
- (GDestroyNotify) g_ptr_array_unref);
g_object_unref (task);
}
@@ -797,12 +779,12 @@ tracker_direct_connection_update_array_async (TrackerSparqlConnection *self,
g_task_run_in_thread (task, update_array_async_thread_func);
}
-static GPtrArray *
+static gboolean
tracker_direct_connection_update_array_finish (TrackerSparqlConnection *self,
GAsyncResult *res,
GError **error)
{
- return g_task_propagate_pointer (G_TASK (res), error);
+ return g_task_propagate_boolean (G_TASK (res), error);
}
static GVariant *
diff --git a/src/libtracker-sparql-backend/tracker-backend.vala
b/src/libtracker-sparql-backend/tracker-backend.vala
index 8b600f5cf..2ef9bccb1 100644
--- a/src/libtracker-sparql-backend/tracker-backend.vala
+++ b/src/libtracker-sparql-backend/tracker-backend.vala
@@ -115,7 +115,7 @@ class Tracker.Sparql.Backend : Connection {
yield bus.update_async (sparql, priority, cancellable);
}
- public async override GenericArray<Sparql.Error?>? update_array_async (string[] sparql, int priority
= GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError, DBusError, GLib.Error
{
+ public async override bool update_array_async (string[] sparql, int priority = GLib.Priority.DEFAULT,
Cancellable? cancellable = null) throws Sparql.Error, IOError, DBusError, GLib.Error {
if (bus == null) {
throw new Sparql.Error.UNSUPPORTED ("Update support not available for direct-only
connection");
}
diff --git a/src/libtracker-sparql/tracker-connection.vala b/src/libtracker-sparql/tracker-connection.vala
index 285d69829..e1fa1ff73 100644
--- a/src/libtracker-sparql/tracker-connection.vala
+++ b/src/libtracker-sparql/tracker-connection.vala
@@ -337,9 +337,7 @@ public abstract class Tracker.Sparql.Connection : Object {
* asynchronous operation is finished.
* @_user_data_: user-defined data to be passed to @_callback_
*
- * Executes asynchronously an array of SPARQL updates. Each update in the
- * array is its own transaction. This means that update n+1 is not halted
- * due to an error in update n.
+ * Executes asynchronously an array of SPARQL updates.
*
* Since: 0.10
*/
@@ -377,19 +375,13 @@ public abstract class Tracker.Sparql.Connection : Object {
* </programlisting>
* </example>
*
- * Returns: a #GPtrArray of size @sparql_length1 with elements that are
- * either NULL or a GError instance. The returned array should be freed with
- * g_ptr_array_unref when no longer used, not with g_ptr_array_free. When
- * you use errors of the array, you must g_error_copy them. Errors inside of
- * the array must be considered as const data and not freed. The index of
- * the error corresponds to the index of the update query in the array that
- * you passed to tracker_sparql_connection_update_array_async.
+ * Returns: %TRUE if the update was successful, %FALSE otherwise.
*
* Since: 0.10
*/
- public async virtual GenericArray<Sparql.Error?>? update_array_async (string[] sparql, int priority =
GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, GLib.Error, GLib.IOError,
DBusError {
+ public async virtual bool update_array_async (string[] sparql, int priority = GLib.Priority.DEFAULT,
Cancellable? cancellable = null) throws Sparql.Error, GLib.Error, GLib.IOError, DBusError {
warning ("Interface 'update_array_async' not implemented");
- return null;
+ return false;
}
/**
diff --git a/tests/tracker-steroids/tracker-test.c b/tests/tracker-steroids/tracker-test.c
index 793541f0d..2d3c260ca 100644
--- a/tests/tracker-steroids/tracker-test.c
+++ b/tests/tracker-steroids/tracker-test.c
@@ -332,23 +332,11 @@ async_update_array_callback (GObject *source_object,
{
GError *error = NULL;
AsyncData *data = user_data;
- GPtrArray *errors;
- errors = tracker_sparql_connection_update_array_finish (connection, result, &error);
+ tracker_sparql_connection_update_array_finish (connection, result, &error);
/* main error is only set on fatal (D-Bus) errors that apply to the whole update */
- g_assert_no_error (error);
-
- g_assert (errors->len == 6);
-
- g_assert (g_ptr_array_index (errors, 0) == NULL);
- g_assert (g_ptr_array_index (errors, 1) == NULL);
- g_assert (g_ptr_array_index (errors, 2) == NULL);
- g_assert (g_ptr_array_index (errors, 3) != NULL);
- g_assert (g_ptr_array_index (errors, 4) == NULL);
- g_assert (g_ptr_array_index (errors, 5) == NULL);
-
- g_ptr_array_unref (errors);
+ g_assert (error != NULL);
g_main_loop_quit (data->main_loop);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]