From 3b6574181e5e0a5d99ed9dcdb5cb9a47af2499d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 1 Apr 2015 00:23:17 +0200 Subject: [PATCH] GH-853 evict asset index files from cache when they don't parse --- logic/OneSixUpdate.cpp | 3 +++ logic/net/HttpMetaCache.cpp | 16 ++++++++++++++++ logic/net/HttpMetaCache.h | 3 +++ 3 files changed, 22 insertions(+) diff --git a/logic/OneSixUpdate.cpp b/logic/OneSixUpdate.cpp index 9d478650..5663484a 100644 --- a/logic/OneSixUpdate.cpp +++ b/logic/OneSixUpdate.cpp @@ -118,6 +118,9 @@ void OneSixUpdate::assetIndexFinished() QString asset_fname = "assets/indexes/" + assetName + ".json"; if (!AssetsUtils::loadAssetsIndexJson(asset_fname, &index)) { + auto metacache = MMC->metacache(); + auto entry = metacache->resolveEntry("asset_indexes", assetName + ".json"); + metacache->evictEntry(entry); emitFailed(tr("Failed to read the assets index!")); } diff --git a/logic/net/HttpMetaCache.cpp b/logic/net/HttpMetaCache.cpp index eb13ee6b..4533a736 100644 --- a/logic/net/HttpMetaCache.cpp +++ b/logic/net/HttpMetaCache.cpp @@ -135,6 +135,17 @@ bool HttpMetaCache::updateEntry(MetaEntryPtr stale_entry) return true; } +bool HttpMetaCache::evictEntry(MetaEntryPtr entry) +{ + if(entry) + { + entry->stale = true; + SaveEventually(); + return true; + } + return false; +} + MetaEntryPtr HttpMetaCache::staleEntry(QString base, QString resource_path) { auto foo = new MetaEntry; @@ -228,6 +239,11 @@ void HttpMetaCache::SaveNow() { for (auto entry : group.entry_list) { + // do not save stale entries. they are dead. + if(entry->stale) + { + continue; + } QJsonObject entryObj; entryObj.insert("base", QJsonValue(entry->base)); entryObj.insert("path", QJsonValue(entry->path)); diff --git a/logic/net/HttpMetaCache.h b/logic/net/HttpMetaCache.h index 55a34165..dd44623c 100644 --- a/logic/net/HttpMetaCache.h +++ b/logic/net/HttpMetaCache.h @@ -51,6 +51,9 @@ public: // add a previously resolved stale entry bool updateEntry(MetaEntryPtr stale_entry); + // evict selected entry from cache + bool evictEntry(MetaEntryPtr entry); + void addBase(QString base, QString base_root); // (re)start a timer that calls SaveNow later.