[gnome-photos/sam/tracker3: 25/27] Fix database updates
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/sam/tracker3: 25/27] Fix database updates
- Date: Thu, 13 Aug 2020 00:11:03 +0000 (UTC)
commit 67192d8c54f1d6a9cd169a7741b5c69e3266e14f
Author: Sam Thursfield <sam afuera me uk>
Date: Thu Aug 13 00:56:27 2020 +0200
Fix database updates
src/photos-query-builder.c | 50 +++++++++++++++++++++++++++++++---------------
src/photos-utils.c | 24 ++++++++++++++++++----
2 files changed, 54 insertions(+), 20 deletions(-)
---
diff --git a/src/photos-query-builder.c b/src/photos-query-builder.c
index 088dd69d..5d37efdc 100644
--- a/src/photos-query-builder.c
+++ b/src/photos-query-builder.c
@@ -129,8 +129,8 @@ photos_query_builder_query (PhotosSearchContextState *state,
"collections_default_filter", collections_default_filter,
"item_pattern", item_pattern,
"photos_default_filter", photos_default_filter,
- "source_filter", source_filter ? source_filter : "",
- "search_filter", search_filter ? search_filter : "",
+ "source_filter", source_filter ? source_filter : "(true)",
+ "search_filter", search_filter ? search_filter : "(true)",
"order", order,
"offset_limit", offset_limit ? offset_limit : "",
NULL);
@@ -145,6 +145,7 @@ photos_query_builder_create_collection_query (PhotosSearchContextState *state,
const gchar *identifier_tag)
{
PhotosQuery *query;
+ g_autoptr (TrackerResource) collection = NULL;
g_autofree gchar *identifier = NULL;
g_autofree gchar *sparql = NULL;
g_autoptr (GDateTime) datetime = NULL;
@@ -157,13 +158,14 @@ photos_query_builder_create_collection_query (PhotosSearchContextState *state,
datetime = g_date_time_new_now_utc ();
time = g_date_time_format_iso8601 (datetime);
- sparql = g_strdup_printf ("INSERT { _:res a nfo:DataContainer ; a nie:DataObject ; "
- "nie:contentLastModified '%s' ; "
- "nie:title '%s' ; "
- "nao:identifier '%s' }",
- time,
- name,
- identifier);
+ collection = tracker_resource_new ("_:res");
+ tracker_resource_add_uri (collection, "rdf:type", "nfo:DataContainer");
+ tracker_resource_add_uri (collection, "rdf:type", "nie:DataObject");
+ tracker_resource_set_string (collection, "nie:contentLastModified", time);
+ tracker_resource_set_string (collection, "nie:title", name);
+ tracker_resource_set_string (collection, "nao:identifier", identifier);
+
+ sparql = tracker_resource_print_sparql_update (collection, NULL, "tracker:Pictures");
query = photos_query_new (state, sparql);
@@ -225,8 +227,8 @@ photos_query_builder_count_query (PhotosSearchContextState *state, gint flags)
"collections_default_filter", collections_default_filter,
"item_pattern", item_pattern,
"photos_default_filter", photos_default_filter,
- "source_filter", source_filter ? source_filter : "",
- "search_filter", search_filter ? search_filter : "",
+ "source_filter", source_filter ? source_filter : "(true)",
+ "search_filter", search_filter ? search_filter : "(true)",
"order", "",
"offset_limit", "",
NULL);
@@ -334,10 +336,19 @@ photos_query_builder_set_collection_query (PhotosSearchContextState *state,
PhotosQuery *query;
g_autofree gchar *sparql = NULL;
- sparql = g_strdup_printf ("%s { <%s> nie:isPartOf <%s> }",
- setting ? "INSERT" : "DELETE",
- item_urn,
- collection_urn);
+ if (setting)
+ sparql = g_strdup_printf ("INSERT DATA { "
+ " GRAPH tracker:Pictures {"
+ " <%s> a nmm:Photo ; "
+ " nie:isPartOf <%s> "
+ " }"
+ "}", item_urn, collection_urn);
+ else
+ sparql = g_strdup_printf ("DELETE DATA { "
+ " GRAPH tracker:Pictures {"
+ " <%s> nie:isPartOf <%s> "
+ " }"
+ "}", item_urn, collection_urn);
query = photos_query_new (state, sparql);
return query;
@@ -372,7 +383,14 @@ photos_query_builder_update_mtime_query (PhotosSearchContextState *state, const
datetime = g_date_time_new_now_utc ();
time = g_date_time_format_iso8601 (datetime);
- sparql = g_strdup_printf ("INSERT OR REPLACE { <%s> nie:contentLastModified '%s' }", resource, time);
+ sparql = g_strdup_printf ("WITH tracker:Pictures "
+ "DELETE { <%s> nie:contentLastModified ?time } "
+ "INSERT { "
+ " <%s> a nmm:Photo ; "
+ " nie:contentLastModified '%s' "
+ "}"
+ "WHERE { <%s> nie:contentLastModified ?time }",
+ resource, resource, time, resource);
query = photos_query_new (state, sparql);
return query;
diff --git a/src/photos-utils.c b/src/photos-utils.c
index c638297b..cc8593d8 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -1261,7 +1261,13 @@ photos_utils_set_edited_name (const gchar *urn, const gchar *title)
g_autoptr (PhotosTrackerQueue) queue = NULL;
g_autofree gchar *sparql = NULL;
- sparql = g_strdup_printf ("INSERT OR REPLACE { <%s> nie:title \"%s\" }", urn, title);
+ sparql = g_strdup_printf ("WITH tracker:Pictures "
+ "DELETE { <%s> nie:title ?title } "
+ "INSERT { "
+ " <%s> a nmm:Photo ; "
+ " nie:title \"%s\" . "
+ "}"
+ "WHERE { <%s> nie:title ?title }", urn, urn, title, urn);
query = photos_query_new (NULL, sparql);
{
@@ -1289,9 +1295,19 @@ photos_utils_set_favorite (const gchar *urn, gboolean is_favorite)
g_autoptr (PhotosTrackerQueue) queue = NULL;
g_autofree gchar *sparql = NULL;
- sparql = g_strdup_printf ("%s { <%s> nao:hasTag nao:predefined-tag-favorite }",
- (is_favorite) ? "INSERT OR REPLACE" : "DELETE",
- urn);
+ if (is_favorite)
+ sparql = g_strdup_printf ("INSERT DATA { "
+ " GRAPH tracker:Pictures {"
+ " <%s> a nmm:Photo ; "
+ " nao:hasTag nao:predefined-tag-favorite "
+ " } "
+ "}", urn);
+ else
+ sparql = g_strdup_printf ("DELETE DATA {"
+ " GRAPH tracker:Pictures {"
+ " <%s> nao:hasTag nao:predefined-tag-favorite "
+ " } "
+ "}", urn);
query = photos_query_new (NULL, sparql);
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]