[gvfs] trash: Check modification time to avoid rereading



commit be29e48e0d90453e115dd1096460ddef8296c8e6
Author: Ondrej Holy <oholy redhat com>
Date:   Wed Mar 9 14:03:00 2016 +0100

    trash: Check modification time to avoid rereading
    
    Rereading of trash dirs is pretty expensive and unfortunately it is
    performed more often with recent changes. Check modification time of
    each trash dir in order to avoid needless rereading, because simple
    query_info call is much faster than enumeration.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=711459

 daemon/trashlib/trashdir.c |   39 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 39 insertions(+), 0 deletions(-)
---
diff --git a/daemon/trashlib/trashdir.c b/daemon/trashlib/trashdir.c
index 897ccac..a11e098 100644
--- a/daemon/trashlib/trashdir.c
+++ b/daemon/trashlib/trashdir.c
@@ -21,6 +21,7 @@ struct OPAQUE_TYPE__TrashDir
   GFile *directory;
   GFile *topdir;
   gboolean is_homedir;
+  GTimeVal mtime;
 
   DirWatch *watch;
   GFileMonitor *monitor;
@@ -49,6 +50,26 @@ compare_basename (gconstpointer a,
 }
 
 static void
+trash_dir_query_mtime (TrashDir *dir, GTimeVal *mtime)
+{
+  GFileInfo *info;
+
+  info = g_file_query_info (dir->directory, G_FILE_ATTRIBUTE_TIME_MODIFIED ","
+                                            G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC,
+                            G_FILE_QUERY_INFO_NONE, NULL, NULL);
+  if (info)
+    {
+      g_file_info_get_modification_time (info, mtime);
+      g_object_unref (info);
+    }
+  else
+    {
+      mtime->tv_sec = 0;
+      mtime->tv_usec = 0;
+    }
+}
+
+static void
 trash_dir_set_files (TrashDir *dir,
                      GSList   *items)
 {
@@ -106,6 +127,7 @@ trash_dir_enumerate (TrashDir *dir)
   GFileEnumerator *enumerator;
   GSList *files = NULL;
 
+  trash_dir_query_mtime (dir, &dir->mtime);
   enumerator = g_file_enumerate_children (dir->directory,
                                           G_FILE_ATTRIBUTE_STANDARD_NAME,
                                           G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
@@ -298,9 +320,26 @@ dir_exists (GFile *directory,
   return result;
 }
 
+static gboolean
+trash_dir_is_dirty (TrashDir *dir)
+{
+  GTimeVal mtime;
+
+  trash_dir_query_mtime (dir, &mtime);
+
+  if (mtime.tv_sec == dir->mtime.tv_sec &&
+      mtime.tv_usec == dir->mtime.tv_usec)
+    return FALSE;
+
+  return TRUE;
+}
+
 void
 trash_dir_rescan (TrashDir *dir)
 {
+  if (!trash_dir_is_dirty (dir))
+    return;
+
   if (dir->watch)
     dir_watch_check (dir->watch);
 


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