From 88cec38df42bb6fde00aaf492fafa3ff55079287 Mon Sep 17 00:00:00 2001 From: Archi Date: Sat, 14 Jan 2023 23:57:45 +0100 Subject: [PATCH] Decrease overhead for calculating tradable sets for announcement We don't care about classIDs there, only amounts --- .../RemoteCommunication.cs | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs index a60ed6b60..5bb01a381 100644 --- a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs +++ b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs @@ -243,7 +243,7 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { HashSet assetsForListing = new(); - Dictionary<(uint RealAppID, Asset.EType Type, Asset.ERarity Rarity), Dictionary> tradableState = new(); + Dictionary<(uint RealAppID, Asset.EType Type, Asset.ERarity Rarity), bool> tradableSets = new(); foreach (Asset item in inventory) { if (acceptedMatchableTypes.Contains(item.Type)) { @@ -256,10 +256,12 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { if (!matchEverything) { (uint RealAppID, Asset.EType Type, Asset.ERarity Rarity) key = (item.RealAppID, item.Type, item.Rarity); - if (tradableState.TryGetValue(key, out Dictionary? set)) { - set[item.ClassID] = set.TryGetValue(item.ClassID, out uint tradableAmount) ? tradableAmount + (item.Tradable ? item.Amount : 0) : item.Tradable ? item.Amount : 0; + if (tradableSets.TryGetValue(key, out bool tradable)) { + if (!tradable && item.Tradable) { + tradableSets[key] = true; + } } else { - tradableState[key] = new Dictionary { { item.ClassID, item.Tradable ? item.Amount : 0 } }; + tradableSets[key] = item.Tradable; } } } @@ -277,18 +279,14 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { // We can now skip sets where we don't have any item to trade with, MatchEverything bots are already filtered to tradable only if (!matchEverything) { - HashSet<(uint RealAppID, Asset.EType Type, Asset.ERarity Rarity)> setsToRemove = tradableState.Where(static set => set.Value.Values.All(static amount => amount == 0)).Select(static set => set.Key).ToHashSet(); + assetsForListing.RemoveWhere(item => tradableSets.TryGetValue((item.RealAppID, item.Type, item.Rarity), out bool tradable) && !tradable); - if (setsToRemove.Count > 0) { - assetsForListing.RemoveWhere(item => setsToRemove.Contains((item.RealAppID, item.Type, item.Rarity))); + if (assetsForListing.Count == 0) { + // We're not eligible, record this as a valid check + LastAnnouncement = DateTime.UtcNow; + ShouldSendAnnouncementEarlier = ShouldSendHeartBeats = false; - if (assetsForListing.Count == 0) { - // We're not eligible, record this as a valid check - LastAnnouncement = DateTime.UtcNow; - ShouldSendAnnouncementEarlier = ShouldSendHeartBeats = false; - - return; - } + return; } }