diff options
author | Ondrej Holy <oholy@redhat.com> | 2016-03-09 14:03:00 +0100 |
---|---|---|
committer | Ondrej Holy <oholy@redhat.com> | 2016-03-31 16:27:19 +0200 |
commit | be29e48e0d90453e115dd1096460ddef8296c8e6 (patch) | |
tree | c0bb6ec5cc230592866b99be93fff90e4e4a9acb | |
parent | 7d0ef03610164e80d15897134d82a8e82bd006a3 (diff) | |
download | gvfs-be29e48e0d90453e115dd1096460ddef8296c8e6.tar.gz |
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
-rw-r--r-- | 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 897ccacd..a11e0980 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); |