[bijiben] Tracker : Complety get rid of sync queries
- From: Pierre-Yves Luyten <pyluyten src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bijiben] Tracker : Complety get rid of sync queries
- Date: Sun, 18 Nov 2012 00:23:24 +0000 (UTC)
commit ba971255b7c743b258d55eb81007f001f74951a9
Author: Pierre-Yves Luyten <py luyten fr>
Date: Sun Nov 18 01:21:42 2012 +0100
Tracker : Complety get rid of sync queries
Tracker is now in better shape but notes tags are "in-memory"
src/libbiji/biji-tracker.c | 131 ++++++++------------------------------------
src/libbiji/biji-tracker.h | 5 --
2 files changed, 23 insertions(+), 113 deletions(-)
---
diff --git a/src/libbiji/biji-tracker.c b/src/libbiji/biji-tracker.c
index b4c5282..fe08466 100644
--- a/src/libbiji/biji-tracker.c
+++ b/src/libbiji/biji-tracker.c
@@ -48,31 +48,10 @@ bjb_perform_query_async (gchar *query,
user_data);
}
-// TODO : remove this one
-static TrackerSparqlCursor *
-bjb_perform_query ( gchar * query )
-{
- TrackerSparqlCursor * result ;
- GError *error = NULL ;
-
- result = tracker_sparql_connection_query (get_connection_singleton(),
- query,
- NULL,
- &error);
-
- if ( error)
- {
- g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"Query error : %s",error->message);
- g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"query was |%s|", query);
- }
-
- return result ;
-}
-
static void
biji_finish_update (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
+ GAsyncResult *res,
+ gpointer user_data)
{
TrackerSparqlConnection *self = TRACKER_SPARQL_CONNECTION (source_object);
GError *error = NULL;
@@ -113,67 +92,6 @@ to_8601_date( gchar * dot_iso_8601_date )
/////////////// Tags
-GList *
-tracker_tag_get_files(gchar *tag)
-{
- GList *result = NULL ;
-
- gchar *query, *value ;
- value = tracker_str (tag);
- query = g_strdup_printf( "SELECT ?s nie:url(?s) nie:mimeType(?s) WHERE \
- { ?s a nfo:FileDataObject;nao:hasTag [nao:prefLabel'%s'] }",
- value );
- g_free (value);
-
- TrackerSparqlCursor *cursor = bjb_perform_query(query) ;
- g_free (query);
-
- if (!cursor)
- {
- return result ;
- }
-
- GString * file ;
- while (tracker_sparql_cursor_next (cursor, NULL, NULL))
- {
- file = g_string_new(tracker_sparql_cursor_get_string(cursor,0,NULL));
- result = g_list_append(result,g_string_free(file,FALSE));
- }
-
- g_object_unref (cursor);
- return result ;
-}
-
-// Count files for one given tag.
-gint
-tracker_tag_get_number_of_files(gchar *tag)
-{
- gchar *query, *value ;
-
- value = tracker_str (tag);
- query = g_strdup_printf( "SELECT ?s nie:url(?s) nie:mimeType(?s) WHERE \
- { ?s a nfo:FileDataObject;nao:hasTag [nao:prefLabel'%s'] }",
- value);
- g_free (value);
-
- TrackerSparqlCursor *cursor = bjb_perform_query(query);
- g_free (query);
- gint result = 0 ;
-
- if (!cursor)
- {
- return result ;
- }
-
- while (tracker_sparql_cursor_next (cursor, NULL, NULL))
- {
- result++;
- }
-
- g_object_unref (cursor);
- return result ;
-}
-
/* This func only provides tags.
* TODO : include number of notes / files */
GList *
@@ -276,6 +194,8 @@ biji_note_delete_from_tracker (BijiNoteObj *note)
g_free ((gchar*) query);
}
+/* There is no standard UPDATE into tracker
+ * delete the note, when we're sure it's done then insert it */
static void
biji_note_create_into_tracker(BijiNoteObj *note)
{
@@ -312,37 +232,32 @@ biji_note_create_into_tracker(BijiNoteObj *note)
g_free(create_date);
g_free(last_change_date);
}
-
-// TODO (?) add time there, eg is_note_tracked ( BijiNoteObj, GDateTime )
-gboolean
-is_note_into_tracker ( BijiNoteObj *note )
-{
- gchar *query = g_strdup_printf ("SELECT ?modDate WHERE { <%s> a nfo:Note ; \
- nie:contentLastModified ?modDate.}",
- biji_note_obj_get_path(note));
- TrackerSparqlCursor *cursor = bjb_perform_query(query);
- g_free (query);
-
- if (!cursor)
- return FALSE ;
+static void
+update_note_into_tracker (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ BijiNoteObj *note = BIJI_NOTE_OBJ (user_data);
- else
- {
- gboolean result = tracker_sparql_cursor_next (cursor, NULL, NULL) ;
- g_object_unref (cursor);
- return result;
- }
+ biji_finish_update (source_object, res, NULL);
+ biji_note_create_into_tracker (note);
}
-// Either create or update
-// FIXME this is probably buggy with async updates
+
void
bijiben_push_note_to_tracker(BijiNoteObj *note)
{
- if ( is_note_into_tracker(note) == TRUE )
- biji_note_delete_from_tracker(note);
+ const gchar *query = g_strdup_printf ("DELETE { <%s> a rdfs:Resource }",
+ biji_note_obj_get_path(note));
+
+ tracker_sparql_connection_update_async (get_connection_singleton(),
+ query,
+ 0, // priority
+ NULL,
+ update_note_into_tracker,
+ note); //user_data
- biji_note_create_into_tracker(note);
+ g_free ((gchar*) query);
}
diff --git a/src/libbiji/biji-tracker.h b/src/libbiji/biji-tracker.h
index e5c480e..6d80e76 100644
--- a/src/libbiji/biji-tracker.h
+++ b/src/libbiji/biji-tracker.h
@@ -24,11 +24,6 @@
#include <libbiji/libbiji.h>
-/* Free the result */
-GList * tracker_tag_get_files(gchar *tag);
-
-gint tracker_tag_get_number_of_files(gchar *tag);
-
/* Get tags */
GList * biji_get_all_tags_finish (GObject *source_object, GAsyncResult *res);
void biji_get_all_tracker_tags_async (GAsyncReadyCallback f, gpointer user_data);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]