Few bug fixes to the caching code, don't allow nulls to get into the cache.

This commit is contained in:
Timothy Baldridge 2019-11-21 06:28:37 -07:00
parent 6892339604
commit 046907499b

View File

@ -236,7 +236,8 @@ namespace Wabbajack.Lib.NexusApi
} }
var result = Get<T>(url); var result = Get<T>(url);
result.ToJSON(cache_file); if (result != null)
result.ToJSON(cache_file);
return result; return result;
} }
@ -374,27 +375,34 @@ namespace Wabbajack.Lib.NexusApi
.ToList(); .ToList();
Utils.Log($"Found {purge.Count} updated mods in the last month"); Utils.Log($"Found {purge.Count} updated mods in the last month");
using (var queue = new WorkQueue())
var to_purge = Directory.EnumerateFiles(LocalCacheDir, "*.json") {
.Select(f => var to_purge = Directory.EnumerateFiles(LocalCacheDir, "*.json")
{ .PMap(queue,f =>
Utils.Status("Cleaning Nexus cache for");
var uri = new Uri(Encoding.UTF8.GetString(Path.GetFileNameWithoutExtension(f).FromHex()));
var parts = uri.PathAndQuery.Split('/', '.').ToHashSet();
var found = purge.FirstOrDefault(p => parts.Contains(p.game.NexusName) && parts.Contains(p.mod.mod_id.ToString()));
if (found != null)
{ {
var should_remove = File.GetLastWriteTimeUtc(f) <= found.mod.latest_file_update.AsUnixTime(); Utils.Status("Cleaning Nexus cache for");
return (should_remove, f); var uri = new Uri(Encoding.UTF8.GetString(Path.GetFileNameWithoutExtension(f).FromHex()));
} var parts = uri.PathAndQuery.Split('/', '.').ToHashSet();
var found = purge.FirstOrDefault(p =>
parts.Contains(p.game.NexusName) && parts.Contains(p.mod.mod_id.ToString()));
if (found != null)
{
var should_remove =
File.GetLastWriteTimeUtc(f) <= found.mod.latest_file_update.AsUnixTime();
return (should_remove, f);
}
return (false, f); if (File.ReadAllText(f).StartsWith("null"))
}) return (true, f);
.Where(p => p.Item1)
.ToList();
Utils.Log($"Purging {to_purge.Count} cache entries"); return (false, f);
to_purge.Do(f => File.Delete(f.f)); })
.Where(p => p.Item1)
.ToList();
Utils.Log($"Purging {to_purge.Count} cache entries");
to_purge.PMap(queue, f => File.Delete(f.f));
}
} }
} }