From 761b46065cd4059510dd048d9a8c312f0d44a801 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Mon, 4 Feb 2019 03:09:20 +0100 Subject: [PATCH] Extra optimization of MatchActively --- ArchiSteamFarm/ArchiWebHandler.cs | 6 +++--- ArchiSteamFarm/Statistics.cs | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index aee4585a2..cd133ce55 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -119,7 +119,7 @@ namespace ArchiSteamFarm { [ItemCanBeNull] [PublicAPI] [SuppressMessage("ReSharper", "FunctionComplexityOverflow")] - public async Task> GetInventory(ulong steamID = 0, uint appID = Steam.Asset.SteamAppID, uint contextID = Steam.Asset.SteamCommunityContextID, bool? tradable = null, IReadOnlyCollection wantedRealAppIDs = null, IReadOnlyCollection wantedTypes = null, IReadOnlyCollection<(uint AppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity)> wantedSets = null, IReadOnlyCollection<(uint AppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity)> skippedSets = null) { + public async Task> GetInventory(ulong steamID = 0, uint appID = Steam.Asset.SteamAppID, uint contextID = Steam.Asset.SteamCommunityContextID, bool? tradable = null, IReadOnlyCollection wantedRealAppIDs = null, IReadOnlyCollection wantedTypes = null, IReadOnlyCollection<(uint RealAppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity)> wantedSets = null) { if ((appID == 0) || (contextID == 0)) { Bot.ArchiLogger.LogNullError(nameof(appID) + " || " + nameof(contextID)); @@ -194,7 +194,7 @@ namespace ArchiSteamFarm { foreach (Steam.Asset asset in response.Assets.Where(asset => asset != null)) { if (descriptions.TryGetValue(asset.ClassID, out (bool Marketable, bool Tradable, uint RealAppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity) description)) { - if ((tradable.HasValue && (description.Tradable != tradable.Value)) || (wantedRealAppIDs?.Contains(description.RealAppID) == false) || (wantedSets?.Contains((description.RealAppID, description.Type, description.Rarity)) == false) || (wantedTypes?.Contains(description.Type) == false) || (skippedSets?.Contains((description.RealAppID, description.Type, description.Rarity)) == true)) { + if ((tradable.HasValue && (description.Tradable != tradable.Value)) || (wantedRealAppIDs?.Contains(description.RealAppID) == false) || (wantedSets?.Contains((description.RealAppID, description.Type, description.Rarity)) == false) || (wantedTypes?.Contains(description.Type) == false)) { continue; } @@ -203,7 +203,7 @@ namespace ArchiSteamFarm { asset.RealAppID = description.RealAppID; asset.Type = description.Type; asset.Rarity = description.Rarity; - } else if (tradable.HasValue || (wantedRealAppIDs != null) || (wantedSets != null) || (wantedTypes != null) || (skippedSets != null)) { + } else if (tradable.HasValue || (wantedRealAppIDs != null) || (wantedSets != null) || (wantedTypes != null)) { continue; } diff --git a/ArchiSteamFarm/Statistics.cs b/ArchiSteamFarm/Statistics.cs index cf6a56abd..e7a4d1187 100644 --- a/ArchiSteamFarm/Statistics.cs +++ b/ArchiSteamFarm/Statistics.cs @@ -321,9 +321,15 @@ namespace ArchiSteamFarm { HashSet<(uint RealAppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity)> skippedSetsThisRound = new HashSet<(uint RealAppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity)>(); foreach (ListedUser listedUser in listedUsers.Where(listedUser => listedUser.MatchEverything && acceptedMatchableTypes.Any(listedUser.MatchableTypes.Contains) && (!triedSteamIDs.TryGetValue(listedUser.SteamID, out (byte Tries, ISet GivenAssetIDs, ISet ReceivedAssetIDs) attempt) || (attempt.Tries < byte.MaxValue)) && !Bot.IsBlacklistedFromTrades(listedUser.SteamID)).OrderBy(listedUser => triedSteamIDs.TryGetValue(listedUser.SteamID, out (byte Tries, ISet GivenAssetIDs, ISet ReceivedAssetIDs) attempt) ? attempt.Tries : 0).ThenByDescending(listedUser => listedUser.Score).Take(MaxMatchedBotsHard)) { + HashSet<(uint RealAppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity)> wantedSets = tradableState.Keys.Where(set => !skippedSetsThisRound.Contains(set) && listedUser.MatchableTypes.Contains(set.Type)).ToHashSet(); + + if (wantedSets.Count == 0) { + continue; + } + Bot.ArchiLogger.LogGenericTrace(listedUser.SteamID + "..."); - HashSet theirInventory = await Bot.ArchiWebHandler.GetInventory(listedUser.SteamID, tradable: true, wantedSets: fullState.Keys, skippedSets: skippedSetsThisRound).ConfigureAwait(false); + HashSet theirInventory = await Bot.ArchiWebHandler.GetInventory(listedUser.SteamID, tradable: true, wantedSets: wantedSets).ConfigureAwait(false); if ((theirInventory == null) || (theirInventory.Count == 0)) { Bot.ArchiLogger.LogGenericTrace(string.Format(Strings.ErrorIsEmpty, nameof(theirInventory)));