From 8cc705feff79be07e4a8afc193ff50a5ab32fbf0 Mon Sep 17 00:00:00 2001 From: Archi Date: Thu, 12 Jan 2023 11:42:04 +0100 Subject: [PATCH] Skip pointless announcements if possible --- .../RemoteCommunication.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs index 0a0dc16b4..58dc54094 100644 --- a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs +++ b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs @@ -45,7 +45,7 @@ using ArchiSteamFarm.Web.Responses; namespace ArchiSteamFarm.OfficialPlugins.ItemsMatcher; internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { - private const byte MaxAnnouncementTTL = 180; // Maximum amount of minutes we can wait before the next Announcement + private const byte MaxAnnouncementTTL = 60; // Maximum amount of minutes we can wait before the next Announcement private const byte MinAnnouncementTTL = 5; // Minimum amount of minutes we must wait before the next Announcement private const byte MinHeartBeatTTL = 10; // Minimum amount of minutes we must wait before sending next HeartBeat private const byte MinItemsCount = 100; // Minimum amount of items to be eligible for public listing @@ -58,6 +58,9 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { Asset.EType.TradingCard ); + // We access this collection only within a semaphore, therefore there is no need for concurrent access + private readonly Dictionary AnnouncedItems = new(); + private readonly Bot Bot; private readonly Timer? HeartBeatTimer; private readonly SemaphoreSlim MatchActivelySemaphore = new(1, 1); @@ -234,6 +237,14 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { return; } + if ((inventory.Count == AnnouncedItems.Count) && inventory.All(item => AnnouncedItems.TryGetValue(item.AssetID, out uint amount) && (item.Amount == amount))) { + // There is nothing new to announce, this is fine, skip the request + LastAnnouncement = DateTime.UtcNow; + ShouldSendAnnouncementEarlier = false; + + return; + } + if (!SignedInWithSteam) { HttpStatusCode? signInWithSteam = await ArchiNet.SignInWithSteam(Bot, WebBrowser).ConfigureAwait(false); @@ -320,6 +331,12 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { ShouldSendAnnouncementEarlier = false; ShouldSendHeartBeats = true; + AnnouncedItems.Clear(); + + foreach (Asset item in inventory) { + AnnouncedItems[item.AssetID] = item.Amount; + } + Bot.ArchiLogger.LogGenericInfo(Strings.Success); } finally { RequestsSemaphore.Release();