Skip to content
Snippets Groups Projects
Commit fb085372 authored by Rye Mutt's avatar Rye Mutt :bread:
Browse files

Small opt to disk cache purge

parent 8a351b04
No related branches found
No related tags found
No related merge requests found
...@@ -72,7 +72,7 @@ void LLDiskCache::purge() ...@@ -72,7 +72,7 @@ void LLDiskCache::purge()
auto start_time = std::chrono::high_resolution_clock::now(); auto start_time = std::chrono::high_resolution_clock::now();
typedef std::pair<std::time_t, std::pair<uintmax_t, std::string>> file_info_t; typedef std::pair<std::time_t, std::pair<uintmax_t, boost::filesystem::path>> file_info_t;
std::vector<file_info_t> file_info; std::vector<file_info_t> file_info;
#if LL_WINDOWS #if LL_WINDOWS
...@@ -89,16 +89,15 @@ void LLDiskCache::purge() ...@@ -89,16 +89,15 @@ void LLDiskCache::purge()
if (entry.path().string().rfind(sCacheFilenameExt) != std::string::npos) if (entry.path().string().rfind(sCacheFilenameExt) != std::string::npos)
{ {
uintmax_t file_size = boost::filesystem::file_size(entry); uintmax_t file_size = boost::filesystem::file_size(entry);
const std::string file_path = entry.path().string();
const std::time_t file_time = boost::filesystem::last_write_time(entry); const std::time_t file_time = boost::filesystem::last_write_time(entry);
file_info.push_back(file_info_t(file_time, { file_size, file_path })); file_info.push_back(file_info_t(file_time, { file_size, entry.path() }));
} }
} }
} }
} }
std::sort(file_info.begin(), file_info.end(), [](file_info_t& x, file_info_t& y) std::sort(file_info.begin(), file_info.end(), [](const file_info_t& x, const file_info_t& y)
{ {
return x.first > y.first; return x.first > y.first;
}); });
...@@ -106,27 +105,23 @@ void LLDiskCache::purge() ...@@ -106,27 +105,23 @@ void LLDiskCache::purge()
LL_INFOS() << "Purging cache to a maximum of " << mMaxSizeBytes << " bytes" << LL_ENDL; LL_INFOS() << "Purging cache to a maximum of " << mMaxSizeBytes << " bytes" << LL_ENDL;
uintmax_t file_size_total = 0; uintmax_t file_size_total = 0;
for (file_info_t& entry : file_info) for (const file_info_t& entry : file_info)
{ {
file_size_total += entry.second.first; file_size_total += entry.second.first;
std::string action = ""; bool remove_file = false;
if (file_size_total > mMaxSizeBytes) if (file_size_total > mMaxSizeBytes)
{ {
action = "DELETE:"; remove_file = true;
boost::filesystem::remove(entry.second.second); boost::filesystem::remove(entry.second.second);
} }
else
{
action = " KEEP:";
}
if (mEnableCacheDebugInfo) if (mEnableCacheDebugInfo)
{ {
// have to do this because of LL_INFO/LL_END weirdness // have to do this because of LL_INFO/LL_END weirdness
std::ostringstream line; std::ostringstream line;
line << action << " "; line << (remove_file ? "DELETE:" : " KEEP:" ) << " ";
line << entry.first << " "; line << entry.first << " ";
line << entry.second.first << " "; line << entry.second.first << " ";
line << entry.second.second; line << entry.second.second;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment