From 4cc37809ddaa7870713dcfd1a42b2639d3ccf4aa Mon Sep 17 00:00:00 2001 From: Interzoneism <113020222+Interzoneism@users.noreply.github.com> Date: Thu, 2 Oct 2025 23:06:22 +0200 Subject: [PATCH] Cache empty craftable scans --- ShowCraftable/ShowCraftable/ShowCraftableModSystem.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ShowCraftable/ShowCraftable/ShowCraftableModSystem.cs b/ShowCraftable/ShowCraftable/ShowCraftableModSystem.cs index 99f31639..ed923091 100644 --- a/ShowCraftable/ShowCraftable/ShowCraftableModSystem.cs +++ b/ShowCraftable/ShowCraftable/ShowCraftableModSystem.cs @@ -67,6 +67,7 @@ public class ShowCraftableSystem : ModSystem private static List s_EmptyPages; private static List StoneTypeTabCache = new(); private static List WoodTypeTabCache = new(); + private static readonly Dictionary TabCachePrimed = new(StringComparer.Ordinal); private static List wildcardGroups = new(); private static readonly Dictionary InflightById = new(); private static readonly Dictionary TabReadyToUpdateUi = new(StringComparer.Ordinal); @@ -564,6 +565,8 @@ private static void SetTabCache(string tabKey, IEnumerable pages) else if (string.Equals(tabKey, WoodTabKeyName, StringComparison.Ordinal)) WoodTypeTabCache = list; else if (string.Equals(tabKey, StoneTabKeyName, StringComparison.Ordinal)) StoneTypeTabCache = list; else CraftableTabCache = list; + + TabCachePrimed[tabKey] = true; } private static List GetTabCacheSnapshot(string tabKey) @@ -2572,6 +2575,7 @@ private static void ClearAllCaches() StoneTypeTabCache = new List(); WoodTypeTabCache = new List(); s_EmptyPages = null; + TabCachePrimed.Clear(); } recipeGroupNeeds = new Dictionary>(); @@ -4145,14 +4149,16 @@ private void OnServerScanReply(CraftScanReply data) } int cachedPages; + bool cachePrimed; lock (CacheLock) { var cache = GetTabCache(tabKey); cachedPages = cache?.Count ?? 0; + cachePrimed = TabCachePrimed.TryGetValue(tabKey, out var primed) && primed; } bool cacheEmpty = cachedPages == 0; - if (dnaMatch && !cacheEmpty) + if (dnaMatch && (cachePrimed || !cacheEmpty)) { SetTabReadyToUpdateUI(tabKey, true); _capi.Event.EnqueueMainThreadTask(() =>