gtksearchenginetracker3: Pre-fill GFileInfo from query
authorCarlos Garnacho <carlosg@gnome.org>
Tue, 19 May 2020 11:55:41 +0000 (13:55 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Tue, 19 May 2020 20:05:07 +0000 (22:05 +0200)
Provide the minimal info necessary. Improves apparent responsiveness
(since we don't visibly clear and repopulate the list) and saves doing
file stat/reads on every file in the result set.

gtk/gtksearchenginetracker3.c

index 1debfc24caeaf7674b60293f1732742d80049cc8..aa50a0dd12daacbfd0dd18fc3a229d0b21bf5527 100644 (file)
 
 #define SEARCH_QUERY_BASE(__PATTERN__)                                 \
   "SELECT ?url "                                                       \
+  "       nfo:fileName(?urn) "                                        \
+  "       nie:mimeType(?urn)"                                         \
+  "       nfo:fileSize(?urn)"                                         \
+  "       nfo:fileLastModified(?urn)"                                 \
   "FROM tracker:FileSystem "                                           \
   "WHERE {"                                                            \
   "  ?urn a nfo:FileDataObject ;"                                      \
@@ -109,6 +113,36 @@ free_hit (gpointer data)
   g_slice_free (GtkSearchHit, hit);
 }
 
+static GFileInfo *
+create_file_info (TrackerSparqlCursor *cursor)
+{
+  GFileInfo *info;
+  const gchar *str;
+  GDateTime *creation;
+
+  info = g_file_info_new ();
+  str = tracker_sparql_cursor_get_string (cursor, 1, NULL);
+  if (str)
+    g_file_info_set_display_name (info, str);
+
+  str = tracker_sparql_cursor_get_string (cursor, 2, NULL);
+  if (str)
+    g_file_info_set_content_type (info, str);
+
+  g_file_info_set_size (info,
+                        tracker_sparql_cursor_get_integer (cursor, 3));
+
+  str = tracker_sparql_cursor_get_string (cursor, 4, NULL);
+  if (str)
+    {
+      creation = g_date_time_new_from_iso8601 (str, NULL);
+      g_file_info_set_modification_date_time (info, creation);
+      g_date_time_unref (creation);
+    }
+
+  return info;
+}
+
 static void
 query_callback (TrackerSparqlStatement *statement,
                 GAsyncResult           *res,
@@ -141,6 +175,7 @@ query_callback (TrackerSparqlStatement *statement,
       url = tracker_sparql_cursor_get_string (cursor, 0, NULL);
       hit = g_slice_new0 (GtkSearchHit);
       hit->file = g_file_new_for_uri (url);
+      hit->info = create_file_info (cursor);
       hits = g_list_prepend (hits, hit);
     }