Description: If max_age and max_size are both -1, thumbnail cleaning
             is disabled, so there is no need to scan the cache
             directories. The referenced bugs concern a serious
             performance issue at login, which is caused by the
             thumbnail cache scan.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=625609
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/gnome-settings-daemon/+bug/505085

diff -Nurp gnome-settings-daemon.orig/plugins/housekeeping/gsd-housekeeping-manager.c gnome-settings-daemon/plugins/housekeeping/gsd-housekeeping-manager.c
--- gnome-settings-daemon.orig/plugins/housekeeping/gsd-housekeeping-manager.c	2013-09-30 15:01:48.825744455 +0100
+++ gnome-settings-daemon/plugins/housekeeping/gsd-housekeeping-manager.c	2013-09-30 15:04:32.537737609 +0100
@@ -225,6 +225,13 @@ purge_thumbnail_cache (GsdHousekeepingMa
 
         g_debug ("housekeeping: checking thumbnail cache size and freshness");
 
+        purge_data.max_age = g_settings_get_int (manager->priv->settings, THUMB_AGE_KEY) * 24 * 60 * 60;
+        purge_data.max_size = g_settings_get_int (manager->priv->settings, THUMB_SIZE_KEY) * 1024 * 1024;
+
+        /* if both are set to -1, we don't need to read anything */
+        if ((purge_data.max_age < 0) && (purge_data.max_size < 0))
+                return;
+
         paths = get_thumbnail_dirs ();
         files = NULL;
         for (i = 0; paths[i] != NULL; i++)
@@ -234,8 +241,6 @@ purge_thumbnail_cache (GsdHousekeepingMa
         g_get_current_time (&current_time);
 
         purge_data.now = current_time.tv_sec;
-        purge_data.max_age = g_settings_get_int (manager->priv->settings, THUMB_AGE_KEY) * 24 * 60 * 60;
-        purge_data.max_size = g_settings_get_int (manager->priv->settings, THUMB_SIZE_KEY) * 1024 * 1024;
         purge_data.total_size = 0;
 
         if (purge_data.max_age >= 0)
