From f041c1eae008210a92adabd142f4db91e35cf3c2 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Sun, 22 Aug 2021 00:17:23 +0200 Subject: [PATCH] :bug: "Fresh" category restored to orig. formula: max 1 day since install. Broken by eb91d9c9dc8701ace5ee11ba0fdba531a4654f69 - since then, freshness was evaluated based on file/ZIP last modified time. The preceding logic was also somewhat complicated - I think the formula was "max 1 day since last cache update which added content", but I'm not sure. Anyway, I restored it to match v0.4.0.7 (year 2013) - Let's gather new feedback. --- source/main/gui/panels/GUI_MainSelector.cpp | 22 ++-------------- source/main/gui/panels/GUI_MainSelector.h | 2 -- source/main/resources/CacheSystem.cpp | 29 +++++++-------------- source/main/resources/CacheSystem.h | 1 + 4 files changed, 12 insertions(+), 42 deletions(-) diff --git a/source/main/gui/panels/GUI_MainSelector.cpp b/source/main/gui/panels/GUI_MainSelector.cpp index a4f54d3f0e..ec564def01 100644 --- a/source/main/gui/panels/GUI_MainSelector.cpp +++ b/source/main/gui/panels/GUI_MainSelector.cpp @@ -426,25 +426,12 @@ void MainSelector::UpdateDisplayLists() query.cqy_filter_guid = m_filter_guid; App::GetCacheSystem()->Query(query); - if (m_selected_cid == CacheCategoryId::CID_All) - { - m_cache_file_freshness = query.cqy_res_last_update; - } m_selected_entry = -1; for (CacheQueryResult const& res: query.cqy_results) { - const bool is_fresh = this->IsEntryFresh(res.cqr_entry); - if (is_fresh) - { - query.cqy_res_category_usage[CacheCategoryId::CID_Fresh]++; - } - - if (m_selected_cid != CacheCategoryId::CID_Fresh || is_fresh) - { - m_display_entries.push_back(res.cqr_entry); - m_selected_entry = 0; - } + m_display_entries.push_back(res.cqr_entry); + m_selected_entry = 0; } // Sort categories alphabetically @@ -463,11 +450,6 @@ void MainSelector::UpdateDisplayLists() } } -bool MainSelector::IsEntryFresh(CacheEntry* entry) -{ - return entry->filetime >= m_cache_file_freshness - 86400; -} - void MainSelector::UpdateSearchParams() { std::string input = m_search_input.ToCStr(); diff --git a/source/main/gui/panels/GUI_MainSelector.h b/source/main/gui/panels/GUI_MainSelector.h index 6eb5732697..555884d3a1 100644 --- a/source/main/gui/panels/GUI_MainSelector.h +++ b/source/main/gui/panels/GUI_MainSelector.h @@ -73,7 +73,6 @@ class MainSelector void UpdateSearchParams(); void Apply(); void Cancel(); - bool IsEntryFresh(CacheEntry* entry); void DrawAttrInt(const char* desc, int val) const; void DrawAttrFloat(const char* desc, float val) const; void DrawAttrSpecial(bool val, const char* label) const; @@ -85,7 +84,6 @@ class MainSelector LoaderType m_loader_type = LT_None; DisplayCategoryVec m_display_categories; DisplayEntryVec m_display_entries; - std::time_t m_cache_file_freshness; CacheSearchMethod m_search_method = CacheSearchMethod::NONE; std::string m_search_string; std::string m_filter_guid; //!< Used for skins diff --git a/source/main/resources/CacheSystem.cpp b/source/main/resources/CacheSystem.cpp index da1bc3db37..c4c3c56bb8 100644 --- a/source/main/resources/CacheSystem.cpp +++ b/source/main/resources/CacheSystem.cpp @@ -1222,6 +1222,7 @@ std::shared_ptr CacheSystem::FetchSkinDef(CacheEntry* cache_entry) size_t CacheSystem::Query(CacheQuery& query) { Ogre::StringUtil::toLowerCase(query.cqy_search_string); + std::time_t cur_time = std::time(nullptr); for (CacheEntry& entry: m_entries) { // Filter by GUID @@ -1256,30 +1257,18 @@ size_t CacheSystem::Query(CacheQuery& query) continue; } + // Category usage stats query.cqy_res_category_usage[entry.categoryid]++; - query.cqy_res_category_usage[CacheCategoryId::CID_All]++; - - // Filter by category - switch (query.cqy_filter_category_id) - { - case CacheCategoryId::CID_Max: - case CacheCategoryId::CID_Hidden: - case CacheCategoryId::CID_SearchResults: - add = false; // Invalid query - skip all. - break; - case CacheCategoryId::CID_All: - case CacheCategoryId::CID_Fresh: - add = true; // Accept all (freshness is filtered externally). - break; + query.cqy_res_category_usage[CacheCategoryId::CID_All]++; - case CacheCategoryId::CID_Unsorted: - default: - add = query.cqy_filter_category_id == entry.categoryid; - break; - } + const bool is_fresh = (cur_time - entry.addtimestamp) < CACHE_FILE_FRESHNESS; + if (is_fresh) + query.cqy_res_category_usage[CacheCategoryId::CID_Fresh]++; - if (!add) + // Filter by category + if ((query.cqy_filter_category_id <= CacheCategoryId::CID_Max && query.cqy_filter_category_id != entry.categoryid) || + (query.cqy_filter_category_id == CID_Fresh && !is_fresh)) { continue; } diff --git a/source/main/resources/CacheSystem.h b/source/main/resources/CacheSystem.h index 29ae36c3b1..30c7527e29 100644 --- a/source/main/resources/CacheSystem.h +++ b/source/main/resources/CacheSystem.h @@ -37,6 +37,7 @@ #define CACHE_FILE "mods.cache" #define CACHE_FILE_FORMAT 11 +#define CACHE_FILE_FRESHNESS 86400 // 60*60*24 = one day namespace RoR {