[nautilus/wip/csoriano/search-popover] search: use nautilus atime and mtime



commit c9f9f82d57666ced4fef81bbc5640212307c4fee
Author: Carlos Soriano <csoriano gnome org>
Date:   Thu Jan 28 12:56:14 2016 +0100

    search: use nautilus atime and mtime
    
    Don't block it with non-async calls to GFile.

 libnautilus-private/nautilus-file.c                |    6 ++++
 libnautilus-private/nautilus-file.h                |    1 +
 libnautilus-private/nautilus-search-engine-model.c |   25 +++----------------
 .../nautilus-search-engine-simple.c                |   16 ++++++------
 4 files changed, 19 insertions(+), 29 deletions(-)
---
diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c
index f52ac5b..1ac017c 100644
--- a/libnautilus-private/nautilus-file.c
+++ b/libnautilus-private/nautilus-file.c
@@ -5057,6 +5057,12 @@ nautilus_file_get_mtime (NautilusFile *file)
        return file->details->mtime;
 }
 
+time_t
+nautilus_file_get_atime (NautilusFile *file)
+{
+        return file->details->atime;
+}
+
 
 static void
 set_attributes_get_info_callback (GObject *source_object,
diff --git a/libnautilus-private/nautilus-file.h b/libnautilus-private/nautilus-file.h
index bfa3209..363fbff 100644
--- a/libnautilus-private/nautilus-file.h
+++ b/libnautilus-private/nautilus-file.h
@@ -170,6 +170,7 @@ char *                  nautilus_file_get_thumbnail_path                (Nautilu
 gboolean                nautilus_file_can_get_size                      (NautilusFile                   
*file);
 goffset                 nautilus_file_get_size                          (NautilusFile                   
*file);
 time_t                  nautilus_file_get_mtime                         (NautilusFile                   
*file);
+time_t                  nautilus_file_get_atime                         (NautilusFile                   
*file);
 GFileType               nautilus_file_get_file_type                     (NautilusFile                   
*file);
 char *                  nautilus_file_get_mime_type                     (NautilusFile                   
*file);
 char *                  nautilus_file_get_extension                     (NautilusFile                   
*file);
diff --git a/libnautilus-private/nautilus-search-engine-model.c 
b/libnautilus-private/nautilus-search-engine-model.c
index 5ae59c5..244a052 100644
--- a/libnautilus-private/nautilus-search-engine-model.c
+++ b/libnautilus-private/nautilus-search-engine-model.c
@@ -158,42 +158,25 @@ model_directory_ready_cb (NautilusDirectory       *directory,
                 if (found && date != NULL) {
                         NautilusQuerySearchType type;
                         guint64 query_time, current_file_time;
-                        const gchar *attrib;
-                        GFileInfo *info;
-                        GError *error;
-                        GFile *location;
 
-                       g_message ("searching for date %s", g_date_time_format (date, "%X"));
 
                         type = nautilus_query_get_search_type (model->details->query);
-                        location = nautilus_file_get_location (file);
-                       error = NULL;
 
                         if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS) {
-                                attrib = G_FILE_ATTRIBUTE_TIME_ACCESS;
+                                current_file_time = nautilus_file_get_atime (file);
                         } else {
-                                attrib = G_FILE_ATTRIBUTE_TIME_MODIFIED;
+                                current_file_time = nautilus_file_get_mtime (file);
                         }
 
-                        query_time = g_date_time_to_unix (date);
 
-                        /* Query current file's attribute */
-                        info = g_file_query_info (location,
-                                                  attrib,
-                                                  G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
-                                                  NULL,
-                                                  &error);
+                        query_time = g_date_time_to_unix (date);
 
-                        if (error) {
+                        if (current_file_time == 0) {
                                 /* Silently ignore errors */
-                                g_clear_error (&error);
                                 found = FALSE;
                         } else {
-                                current_file_time = g_file_info_get_attribute_uint64 (info, attrib);
                                 found = (query_time <= current_file_time);
                         }
-
-                        g_clear_object (&location);
                 }
 
                if (found) {
diff --git a/libnautilus-private/nautilus-search-engine-simple.c 
b/libnautilus-private/nautilus-search-engine-simple.c
index 9468269..b43fd63 100644
--- a/libnautilus-private/nautilus-search-engine-simple.c
+++ b/libnautilus-private/nautilus-search-engine-simple.c
@@ -211,6 +211,8 @@ visit_directory (GFile *dir, SearchThreadData *data)
        GList *l;
        const char *id;
        gboolean visited;
+       guint64 atime;
+       guint64 mtime;
 
        enumerator = g_file_enumerate_children (dir,
                                                data->mime_types != NULL ?
@@ -253,30 +255,29 @@ visit_directory (GFile *dir, SearchThreadData *data)
                        }
                }
 
+               mtime = g_file_info_get_attribute_uint64 (info, "time::modified");
+               atime = g_file_info_get_attribute_uint64 (info, "time::access");
                 if (found && nautilus_query_get_date (data->query) != NULL) {
                         NautilusQuerySearchType type;
-                        GDateTime *date;
                         guint64 current_file_time, query_time;
-                        const gchar *attrib;
+                       GDateTime *date;
 
                         type = nautilus_query_get_search_type (data->query);
 
                         if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS) {
-                                attrib = G_FILE_ATTRIBUTE_TIME_ACCESS;
+                                current_file_time = atime;
                         } else {
-                                attrib = G_FILE_ATTRIBUTE_TIME_MODIFIED;
+                                current_file_time = mtime;
                         }
 
                         date = nautilus_query_get_date (data->query);
                         query_time = g_date_time_to_unix (date);
-                        current_file_time = g_file_info_get_attribute_uint64 (info, attrib);
 
                         found = (query_time <= current_file_time);
                 }
                
                if (found) {
                        NautilusSearchHit *hit;
-                       GTimeVal tv;
                        GDateTime *date;
                        char *uri;
 
@@ -284,8 +285,7 @@ visit_directory (GFile *dir, SearchThreadData *data)
                        hit = nautilus_search_hit_new (uri);
                        g_free (uri);
                        nautilus_search_hit_set_fts_rank (hit, match);
-                       g_file_info_get_modification_time (info, &tv);
-                       date = g_date_time_new_from_timeval_local (&tv);
+                       date = g_date_time_new_from_unix_local (mtime);
                        nautilus_search_hit_set_modification_time (hit, date);
                        g_date_time_unref (date);
 


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