[grilo-plugins/wip/carlosg/tracker3: 11/40] tracker3: Clean up tracking of multiple data sources



commit ee20b4696165a2ed667a9dea0104d2c4d846e339
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed May 20 03:26:45 2020 +0200

    tracker3: Clean up tracking of multiple data sources
    
    We only have one source, with name "". This was unused.

 src/tracker3/grl-tracker-source-api.c  | 71 +++++++++-------------------------
 src/tracker3/grl-tracker-source-priv.h |  1 -
 src/tracker3/grl-tracker-source.c      | 71 ----------------------------------
 src/tracker3/grl-tracker-utils.c       | 11 ------
 4 files changed, 18 insertions(+), 136 deletions(-)
---
diff --git a/src/tracker3/grl-tracker-source-api.c b/src/tracker3/grl-tracker-source-api.c
index 59dc1cf2..af7f5d71 100644
--- a/src/tracker3/grl-tracker-source-api.c
+++ b/src/tracker3/grl-tracker-source-api.c
@@ -63,7 +63,7 @@ GRL_LOG_DOMAIN_STATIC(tracker_source_result_log_domain);
 
 #define TRACKER_QUERY_PARTIAL_REQUEST           \
   "SELECT rdf:type(?urn) %s "                   \
-  "WHERE { %s . %s } "                          \
+  "WHERE { %s } "                               \
   "ORDER BY DESC(nfo:fileLastModified(?urn)) "  \
   TRACKER_QUERY_LIMIT
 
@@ -78,7 +78,7 @@ GRL_LOG_DOMAIN_STATIC(tracker_source_result_log_domain);
   "%s "                                         \
   "?urn tracker:available ?tr . "               \
   "?urn fts:match \"%s\" . "                    \
-  "%s %s "                                      \
+  "%s "                                         \
   "} "                                          \
   "ORDER BY DESC(nfo:fileLastModified(?urn)) "  \
   TRACKER_QUERY_LIMIT
@@ -87,7 +87,6 @@ GRL_LOG_DOMAIN_STATIC(tracker_source_result_log_domain);
   "SELECT DISTINCT rdf:type(?urn) %s "          \
   "WHERE "                                      \
   "{ "                                          \
-  "%s "                                         \
   "?urn tracker:available ?tr . "               \
   "%s %s "                                      \
   "} "                                          \
@@ -102,7 +101,6 @@ GRL_LOG_DOMAIN_STATIC(tracker_source_result_log_domain);
   "?urn nie:isStoredAs ?file . "                \
   "?file tracker:available ?tr . "              \
   "%s "                                         \
-  "%s "                                         \
   "} "                                          \
   "ORDER BY DESC(nfo:fileLastModified(?urn)) "  \
   TRACKER_QUERY_LIMIT
@@ -138,7 +136,6 @@ GRL_LOG_DOMAIN_STATIC(tracker_source_result_log_domain);
   "?urn nie:url \"%s\" ; "                              \
   "tracker:available true ; "                           \
   "a nfo:Media . "                                      \
-  "%s "                                                 \
   "}"
 
 #define TRACKER_MEDIA_FROM_URI_REQUEST          \
@@ -147,7 +144,6 @@ GRL_LOG_DOMAIN_STATIC(tracker_source_result_log_domain);
   "{ "                                          \
   "?urn nie:url \"%s\" ; "                      \
   "tracker:available ?tr . "                    \
-  "%s "                                         \
   "} "                                          \
 
 /**/
@@ -757,7 +753,6 @@ grl_tracker_source_query (GrlSource *source,
 {
   GError               *error = NULL;
   GrlTrackerSourcePriv *priv  = GRL_TRACKER_SOURCE_GET_PRIVATE (source);
-  gchar                *constraint;
   gchar                *sparql_final;
   gchar                *sparql_select;
   GrlTrackerOp         *os;
@@ -776,15 +771,12 @@ grl_tracker_source_query (GrlSource *source,
 
   /* Check if it is a full sparql query */
   if (g_ascii_strncasecmp (qs->query, "select ", 7) != 0) {
-    constraint = grl_tracker_source_get_device_constraint (priv);
     sparql_select = grl_tracker_source_get_select_string (qs->keys);
     sparql_final = g_strdup_printf (TRACKER_QUERY_PARTIAL_REQUEST,
                                     sparql_select,
                                     qs->query,
-                                    constraint,
                                     skip,
                                     count);
-    g_free (constraint);
     g_free (qs->query);
     g_free (sparql_select);
     qs->query = sparql_final;
@@ -832,7 +824,7 @@ grl_tracker_source_resolve (GrlSource *source,
                             GrlSourceResolveSpec *rs)
 {
   GrlTrackerSourcePriv *priv               = GRL_TRACKER_SOURCE_GET_PRIVATE (source);
-  gchar                *constraint         = NULL, *sparql_select, *sparql_final;
+  gchar                *sparql_select, *sparql_final;
   gchar                *sparql_type_filter = NULL;
   const gchar          *url                = grl_media_get_url (rs->media);
   GrlTrackerOp         *os;
@@ -840,25 +832,18 @@ grl_tracker_source_resolve (GrlSource *source,
 
   GRL_IDEBUG ("%s: id=%i", __FUNCTION__, rs->operation_id);
 
-  /* Check if the media comes from this source or another */
-  if (g_strcmp0 (priv->tracker_datasource, grl_source_get_id (rs->source)) == 0) {
-    if (grl_media_get_id (rs->media) == NULL) {
-      rs->callback (rs->source, rs->operation_id, rs->media, rs->user_data, NULL);
-      return;
-    } else {
-      sparql_select = grl_tracker_source_get_select_string (rs->keys);
-      sparql_final = g_strdup_printf (TRACKER_RESOLVE_REQUEST, sparql_select,
-                                      grl_media_get_id (rs->media));
-    }
+  if (grl_media_get_id (rs->media) != NULL) {
+    sparql_select = grl_tracker_source_get_select_string (rs->keys);
+    sparql_final = g_strdup_printf (TRACKER_RESOLVE_REQUEST, sparql_select,
+                                    grl_media_get_id (rs->media));
+  } else if (grl_media_get_url (rs->media) != NULL) {
+    sparql_select = grl_tracker_source_get_select_string (rs->keys);
+    sparql_final = g_strdup_printf (TRACKER_RESOLVE_URL_REQUEST,
+                                    sparql_select,
+                                    grl_media_get_url (rs->media));
   } else {
-    if (url) {
-      sparql_select = grl_tracker_source_get_select_string (rs->keys);
-      sparql_final = g_strdup_printf (TRACKER_RESOLVE_URL_REQUEST,
-                                      sparql_select, url);
-    } else {
-      rs->callback (rs->source, rs->operation_id, rs->media, rs->user_data, NULL);
-      return;
-    }
+    rs->callback (rs->source, rs->operation_id, rs->media, rs->user_data, NULL);
+    return;
   }
 
   GRL_IDEBUG ("\request: '%s'", sparql_final);
@@ -876,7 +861,6 @@ grl_tracker_source_resolve (GrlSource *source,
   grl_tracker_queue_push (grl_tracker_queue, os);
 
   g_clear_pointer (&sparql_type_filter, g_free);
-  g_clear_pointer (&constraint, g_free);
   g_clear_pointer (&sparql_select, g_free);
   g_clear_object (&statement);
 }
@@ -889,10 +873,6 @@ grl_tracker_source_may_resolve (GrlSource *source,
 {
   GRL_IDEBUG ("%s: key=%s", __FUNCTION__, GRL_METADATA_KEY_GET_NAME (key_id));
 
-  if (media && grl_tracker_source_find_source (grl_media_get_source (media))) {
-    return TRUE;
-  }
-
   if (!grl_tracker_key_is_supported (key_id)) {
     return FALSE;
   }
@@ -955,7 +935,6 @@ void
 grl_tracker_source_search (GrlSource *source, GrlSourceSearchSpec *ss)
 {
   GrlTrackerSourcePriv *priv  = GRL_TRACKER_SOURCE_GET_PRIVATE (source);
-  gchar                *constraint;
   gchar                *sparql_select;
   gchar                *sparql_final;
   gchar                *sparql_type_filter;
@@ -969,7 +948,6 @@ grl_tracker_source_search (GrlSource *source, GrlSourceSearchSpec *ss)
 
   GRL_IDEBUG ("%s: id=%u", __FUNCTION__, ss->operation_id);
 
-  constraint = grl_tracker_source_get_device_constraint (priv);
   sparql_select = grl_tracker_source_get_select_string (ss->keys);
   sparql_type_filter = get_sparql_type_filter (ss->options, FALSE);
   grl_tracker_source_get_duration_min_max (ss->options, &min_dur, &max_dur);
@@ -977,13 +955,13 @@ grl_tracker_source_search (GrlSource *source, GrlSourceSearchSpec *ss)
   if (!ss->text || ss->text[0] == '\0') {
     /* Search all */
     sparql_final = g_strdup_printf (TRACKER_SEARCH_ALL_REQUEST, sparql_select,
-                                    constraint, duration_constraint, sparql_type_filter,
+                                    duration_constraint, sparql_type_filter,
                                     skip, count);
   } else {
     escaped_text = tracker_sparql_escape_string (ss->text);
     sparql_final = g_strdup_printf (TRACKER_SEARCH_REQUEST, sparql_select,
                                     sparql_type_filter, escaped_text,
-                                    constraint, duration_constraint, skip, count);
+                                    duration_constraint, skip, count);
     g_free (escaped_text);
   }
 
@@ -1005,7 +983,6 @@ grl_tracker_source_search (GrlSource *source, GrlSourceSearchSpec *ss)
 
   grl_tracker_queue_push (grl_tracker_queue, os);
 
-  g_free (constraint);
   g_free (sparql_select);
   g_free (sparql_type_filter);
   g_free (duration_constraint);
@@ -1027,7 +1004,6 @@ grl_tracker_source_browse_category (GrlSource *source,
                                     GrlSourceBrowseSpec *bs)
 {
   GrlTrackerSourcePriv *priv  = GRL_TRACKER_SOURCE_GET_PRIVATE (source);
-  gchar                *constraint;
   gchar                *sparql_select;
   gchar                *sparql_final;
   GrlTrackerOp         *os;
@@ -1154,12 +1130,10 @@ grl_tracker_source_browse_category (GrlSource *source,
 
   grl_tracker_source_get_duration_min_max (bs->options, &min_dur, &max_dur);
   duration_constraint = grl_tracker_source_create_constraint (min_dur, max_dur);
-  constraint = grl_tracker_source_get_device_constraint (priv);
   sparql_select = grl_tracker_source_get_select_string (bs->keys);
   sparql_final = g_strdup_printf (TRACKER_BROWSE_CATEGORY_REQUEST,
                                   sparql_select,
                                   category,
-                                  constraint,
                                   duration_constraint,
                                   skip, count);
 
@@ -1181,7 +1155,6 @@ grl_tracker_source_browse_category (GrlSource *source,
 
   grl_tracker_queue_push (grl_tracker_queue, os);
 
-  g_free (constraint);
   g_free (sparql_select);
   g_free (duration_constraint);
   g_clear_object (&statement);
@@ -1298,19 +1271,15 @@ grl_tracker_source_test_media_from_uri (GrlSource *source,
   GError               *error = NULL;
   TrackerSparqlCursor  *cursor;
   gboolean              empty;
-  gchar                *constraint;
   gchar                *sparql_final;
 
-  constraint = grl_tracker_source_get_device_constraint (priv);
   sparql_final = g_strdup_printf (TRACKER_TEST_MEDIA_FROM_URI_REQUEST,
-                                  uri,
-                                  constraint);
+                                  uri);
 
   cursor = tracker_sparql_connection_query (grl_tracker_connection,
                                             sparql_final,
                                             NULL,
                                             &error);
-  g_free (constraint);
   g_free (sparql_final);
 
   if (error) {
@@ -1337,7 +1306,6 @@ grl_tracker_source_get_media_from_uri (GrlSource *source,
                                        GrlSourceMediaFromUriSpec *mfus)
 {
   GrlTrackerSourcePriv *priv  = GRL_TRACKER_SOURCE_GET_PRIVATE (source);
-  gchar                *constraint;
   gchar                *sparql_select;
   gchar                *sparql_final;
   GrlTrackerOp         *os;
@@ -1349,12 +1317,10 @@ grl_tracker_source_get_media_from_uri (GrlSource *source,
   if (!g_list_find (mfus->keys, GRLKEYID_TO_POINTER (GRL_METADATA_KEY_ID)))
     mfus->keys = g_list_prepend (mfus->keys, GRLKEYID_TO_POINTER (GRL_METADATA_KEY_ID));
 
-  constraint = grl_tracker_source_get_device_constraint (priv);
   sparql_select = grl_tracker_source_get_select_string (mfus->keys);
   sparql_final = g_strdup_printf (TRACKER_MEDIA_FROM_URI_REQUEST,
                                   sparql_select,
-                                  mfus->uri,
-                                  constraint);
+                                  mfus->uri);
 
   GRL_IDEBUG ("\tselect: '%s'", sparql_final);
 
@@ -1370,7 +1336,6 @@ grl_tracker_source_get_media_from_uri (GrlSource *source,
 
   grl_tracker_queue_push (grl_tracker_queue, os);
 
-  g_free (constraint);
   g_free (sparql_select);
   g_clear_object (&statement);
 }
diff --git a/src/tracker3/grl-tracker-source-priv.h b/src/tracker3/grl-tracker-source-priv.h
index 7016b6e6..eeaad962 100644
--- a/src/tracker3/grl-tracker-source-priv.h
+++ b/src/tracker3/grl-tracker-source-priv.h
@@ -68,7 +68,6 @@ struct _GrlTrackerSourcePriv {
   GHashTable *operations;
   GrlTrackerSourceNotify *notifier;
 
-  gchar *tracker_datasource;
   gboolean notify_changes;
 
   GrlTrackerSourceState state;
diff --git a/src/tracker3/grl-tracker-source.c b/src/tracker3/grl-tracker-source.c
index c0b245f2..d2a535ef 100644
--- a/src/tracker3/grl-tracker-source.c
+++ b/src/tracker3/grl-tracker-source.c
@@ -55,7 +55,6 @@ GRL_LOG_DOMAIN_STATIC(tracker_source_log_domain);
 enum {
   PROP_0,
   PROP_TRACKER_CONNECTION,
-  PROP_TRACKER_DATASOURCE,
 };
 
 static void grl_tracker_source_set_property (GObject      *object,
@@ -71,7 +70,6 @@ static void grl_tracker_source_constructed (GObject *object);
 
 /* shared data across  */
 GrlTrackerCache *grl_tracker_item_cache;
-GHashTable *grl_tracker_source_sources;
 
 /* ================== TrackerSource GObject ================ */
 
@@ -87,7 +85,6 @@ grl_tracker_source_new (TrackerSparqlConnection *connection)
                        "source-name", GRL_TRACKER_SOURCE_NAME,
                        "source-desc", GRL_TRACKER_SOURCE_DESC,
                        "tracker-connection", connection,
-                       "tracker-datasource", "",
                        NULL);
 }
 
@@ -127,16 +124,6 @@ grl_tracker_source_class_init (GrlTrackerSourceClass * klass)
                                                         | G_PARAM_CONSTRUCT_ONLY
                                                         | G_PARAM_STATIC_NAME));
 
- g_object_class_install_property (g_class,
-                                  PROP_TRACKER_DATASOURCE,
-                                  g_param_spec_string ("tracker-datasource",
-                                                       "tracker datasource",
-                                                       "A Tracker nie:DataSource URN",
-                                                       NULL,
-                                                       G_PARAM_WRITABLE
-                                                       | G_PARAM_CONSTRUCT_ONLY
-                                                       | G_PARAM_STATIC_NAME));
-
   g_type_class_add_private (klass, sizeof (GrlTrackerSourcePriv));
 }
 
@@ -190,28 +177,11 @@ grl_tracker_source_set_property (GObject      *object,
       priv->tracker_connection = g_object_ref (g_value_get_object (value));
       break;
 
-    case PROP_TRACKER_DATASOURCE:
-      g_clear_pointer (&priv->tracker_datasource, g_free);
-      priv->tracker_datasource = g_strdup (g_value_get_string (value));
-      break;
-
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
   }
 }
 
-const gchar *
-grl_tracker_source_get_tracker_source (GrlTrackerSource *source)
-{
-  GrlTrackerSourcePriv *priv;
-
-  g_return_val_if_fail (GRL_IS_TRACKER_SOURCE (source), NULL);
-
-  priv = source->priv;
-
-  return priv->tracker_datasource;
-}
-
 TrackerSparqlConnection *
 grl_tracker_source_get_tracker_connection (GrlTrackerSource *source)
 {
@@ -234,9 +204,6 @@ grl_tracker_add_source (GrlTrackerSource *source)
   GRL_DEBUG ("====================>add source '%s'",
              grl_source_get_name (GRL_SOURCE (source)));
 
-  g_hash_table_insert (grl_tracker_source_sources,
-                       (gpointer) grl_tracker_source_get_tracker_source (source),
-                       g_object_ref (source));
   priv->state = GRL_TRACKER_SOURCE_STATE_RUNNING;
   grl_registry_register_source (grl_registry_get_default (),
                                 grl_tracker_plugin,
@@ -252,8 +219,6 @@ grl_tracker_del_source (GrlTrackerSource *source)
   GRL_DEBUG ("==================>del source '%s'",
              grl_source_get_name (GRL_SOURCE (source)));
 
-  g_hash_table_remove (grl_tracker_source_sources,
-                       grl_tracker_source_get_tracker_source (source));
   grl_tracker_source_cache_del_source (grl_tracker_item_cache, source);
   priv->state = GRL_TRACKER_SOURCE_STATE_DELETED;
   grl_registry_unregister_source (grl_registry_get_default (),
@@ -272,40 +237,6 @@ grl_tracker_source_can_notify (GrlTrackerSource *source)
   return FALSE;
 }
 
-GrlTrackerSource *
-grl_tracker_source_find (const gchar *id)
-{
-  GrlTrackerSource *source;
-
-  source = g_hash_table_lookup (grl_tracker_source_sources, id);
-  return source;
-}
-
-static gboolean
-match_plugin_id (gpointer key,
-                 gpointer value,
-                 gpointer user_data)
-{
-  if (g_strcmp0 (grl_source_get_id (GRL_SOURCE (value)),
-                 (gchar *) user_data) == 0) {
-    return TRUE;
-  }
-
-  return FALSE;
-}
-
-/* Search for registered plugin with @id */
-GrlTrackerSource *
-grl_tracker_source_find_source (const gchar *id)
-{
-  GrlTrackerSource *source;
-
-  source = g_hash_table_find (grl_tracker_source_sources,
-                              match_plugin_id,
-                              (gpointer) id);
-  return source;
-}
-
 void
 grl_tracker_source_sources_init (void)
 {
@@ -316,8 +247,6 @@ grl_tracker_source_sources_init (void)
 
   grl_tracker_item_cache =
     grl_tracker_source_cache_new (TRACKER_ITEM_CACHE_SIZE);
-  grl_tracker_source_sources = g_hash_table_new_full (g_str_hash, g_str_equal,
-                                                      NULL, g_object_unref);
 
   if (grl_tracker_connection != NULL) {
     GrlTrackerSource *source;
diff --git a/src/tracker3/grl-tracker-utils.c b/src/tracker3/grl-tracker-utils.c
index 6b5c7980..67ae46c6 100644
--- a/src/tracker3/grl-tracker-utils.c
+++ b/src/tracker3/grl-tracker-utils.c
@@ -491,17 +491,6 @@ grl_tracker_key_is_supported (const GrlKeyID key)
 
 /**/
 
-gchar *
-grl_tracker_source_get_device_constraint (GrlTrackerSourcePriv *priv)
-{
-  if (priv->tracker_datasource == NULL ||
-      priv->tracker_datasource[0] == '\0')
-    return g_strdup ("");
-
-  return g_strdup_printf ("?urn nie:dataSource <%s> .",
-                          priv->tracker_datasource);
-}
-
 gchar *
 grl_tracker_source_get_select_string (const GList *keys)
 {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]