From e91df4d59f6405f1e7b2da1e98704feb11c43596 Mon Sep 17 00:00:00 2001 From: heckflosse Date: Tue, 11 Dec 2018 15:57:17 +0100 Subject: [PATCH] Closing RT is slow on Windows when cache folder contains a lot of files, fixes #5083 --- rtgui/cachemanager.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/rtgui/cachemanager.cc b/rtgui/cachemanager.cc index 5f73e9e0f..d86f6c41f 100644 --- a/rtgui/cachemanager.cc +++ b/rtgui/cachemanager.cc @@ -339,6 +339,25 @@ Glib::ustring CacheManager::getCacheFileName (const Glib::ustring& subDir, void CacheManager::applyCacheSizeLimitation () const { + // first count files without fetching file name and timestamp. + std::size_t numFiles = 0; + try { + + const auto dirName = Glib::build_filename (baseDir, "data"); + const auto dir = Gio::File::create_for_path (dirName); + + auto enumerator = dir->enumerate_children (""); + + while (numFiles <= options.maxCacheEntries && enumerator->next_file ()) { + ++numFiles; + } + + } catch (Glib::Exception&) {} + + if (numFiles <= options.maxCacheEntries) { + return; + } + using FNameMTime = std::pair; std::vector files;