[gnome-online-miners] gdata: Don't create a separate nfo:Equipment for each photo
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-online-miners] gdata: Don't create a separate nfo:Equipment for each photo
- Date: Fri, 2 Sep 2016 08:21:07 +0000 (UTC)
commit 88626bf3e0786bcf4aeacae0b45cae1bee24b441
Author: Debarshi Ray <debarshir gnome org>
Date: Wed Aug 31 18:17:06 2016 +0200
gdata: Don't create a separate nfo:Equipment for each photo
https://bugzilla.gnome.org/show_bug.cgi?id=770658
src/gom-gdata-miner.c | 29 +++--------------
src/gom-tracker.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++
src/gom-tracker.h | 6 +++
3 files changed, 94 insertions(+), 24 deletions(-)
---
diff --git a/src/gom-gdata-miner.c b/src/gom-gdata-miner.c
index 2d87aa8..7695d78 100644
--- a/src/gom-gdata-miner.c
+++ b/src/gom-gdata-miner.c
@@ -552,30 +552,11 @@ account_miner_job_process_photo (GomAccountMinerJob *job,
if (make != NULL || model != NULL)
{
- equipment_resource = gom_tracker_sparql_connection_ensure_resource
- (job->connection,
- job->cancellable, error,
- &resource_exists,
- job->datasource_urn, resource,
- "nfo:Equipment", NULL);
-
- if (*error != NULL)
- goto out;
-
- gom_tracker_sparql_connection_insert_or_replace_triple
- (job->connection,
- job->cancellable, error,
- job->datasource_urn, equipment_resource,
- "nfo:manufacturer", make);
-
- if (*error != NULL)
- goto out;
-
- gom_tracker_sparql_connection_insert_or_replace_triple
- (job->connection,
- job->cancellable, error,
- job->datasource_urn, equipment_resource,
- "nfo:model", model);
+ equipment_resource = gom_tracker_utils_ensure_equipment_resource (job->connection,
+ job->cancellable,
+ error,
+ make,
+ model);
if (*error != NULL)
goto out;
diff --git a/src/gom-tracker.c b/src/gom-tracker.c
index 59d5ce2..68818c4 100644
--- a/src/gom-tracker.c
+++ b/src/gom-tracker.c
@@ -393,6 +393,89 @@ gom_tracker_utils_ensure_contact_resource (TrackerSparqlConnection *connection,
return retval;
}
+gchar *
+gom_tracker_utils_ensure_equipment_resource (TrackerSparqlConnection *connection,
+ GCancellable *cancellable,
+ GError **error,
+ const gchar *make,
+ const gchar *model)
+{
+ GError *local_error;
+ TrackerSparqlCursor *cursor = NULL;
+ gboolean res;
+ gchar *equip_uri = NULL;
+ gchar *insert = NULL;
+ gchar *retval = NULL;
+ gchar *select = NULL;
+
+ g_return_val_if_fail (TRACKER_SPARQL_IS_CONNECTION (connection), NULL);
+ g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+ g_return_val_if_fail (make != NULL || model != NULL, NULL);
+
+ equip_uri = tracker_sparql_escape_uri_printf ("urn:equipment:%s:%s:",
+ make != NULL ? make : "",
+ model != NULL ? model : "");
+ select = g_strdup_printf ("SELECT <%s> WHERE { }", equip_uri);
+
+ local_error = NULL;
+ cursor = tracker_sparql_connection_query (connection, select, cancellable, &local_error);
+ if (local_error != NULL)
+ {
+ g_propagate_error (error, local_error);
+ goto out;
+ }
+
+ local_error = NULL;
+ res = tracker_sparql_cursor_next (cursor, cancellable, &local_error);
+ if (local_error != NULL)
+ {
+ g_propagate_error (error, local_error);
+ goto out;
+ }
+
+ if (res)
+ {
+ const gchar *cursor_uri;
+
+ cursor_uri = tracker_sparql_cursor_get_string (cursor, 0, NULL);
+ if (g_strcmp0 (cursor_uri, equip_uri) == 0)
+ {
+ /* return the found resource */
+ retval = g_strdup (cursor_uri);
+ g_debug ("Found resource in the store: %s", retval);
+ goto out;
+ }
+ }
+
+ /* not found, create the resource */
+ insert = g_strdup_printf ("INSERT { <%s> a nfo:Equipment ; nfo:manufacturer \"%s\" ; nfo:model \"%s\" }",
+ equip_uri,
+ make,
+ model);
+
+ local_error = NULL;
+ tracker_sparql_connection_update (connection, insert, G_PRIORITY_DEFAULT, cancellable, &local_error);
+ if (local_error != NULL)
+ {
+ g_propagate_error (error, local_error);
+ goto out;
+ }
+
+ retval = equip_uri;
+ equip_uri = NULL;
+
+ g_debug ("Created a new equipment resource: %s", retval);
+
+ out:
+ g_clear_object (&cursor);
+ g_free (equip_uri);
+ g_free (insert);
+ g_free (select);
+
+ return retval;
+}
+
void
gom_tracker_update_datasource (TrackerSparqlConnection *connection,
const gchar *datasource_urn,
diff --git a/src/gom-tracker.h b/src/gom-tracker.h
index 6f0a244..94a39e8 100644
--- a/src/gom-tracker.h
+++ b/src/gom-tracker.h
@@ -66,6 +66,12 @@ gchar* gom_tracker_utils_ensure_contact_resource (TrackerSparqlConnection *conne
const gchar *email,
const gchar *fullname);
+gchar *gom_tracker_utils_ensure_equipment_resource (TrackerSparqlConnection *connection,
+ GCancellable *cancellable,
+ GError **error,
+ const gchar *make,
+ const gchar *model);
+
void gom_tracker_update_datasource (TrackerSparqlConnection *connection,
const gchar *datasource_urn,
gboolean resource_exists,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]