Skip to content

Commit

Permalink
🐛 "Fresh" category restored to orig. formula: max 1 day since install.
Browse files Browse the repository at this point in the history
Broken by eb91d9c - 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.
  • Loading branch information
ohlidalp committed Aug 21, 2021
1 parent e8b79f6 commit 09160fb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 42 deletions.
22 changes: 2 additions & 20 deletions source/main/gui/panels/GUI_MainSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down
2 changes: 0 additions & 2 deletions source/main/gui/panels/GUI_MainSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
29 changes: 9 additions & 20 deletions source/main/resources/CacheSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,7 @@ std::shared_ptr<SkinDef> 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
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions source/main/resources/CacheSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down

0 comments on commit 09160fb

Please # to comment.