From d2da28336ed95585e69ae42272252562a6b63a2c Mon Sep 17 00:00:00 2001 From: HaruhiSuzumiyah <68439343+HaruhiSuzumiyah@users.noreply.github.com> Date: Sat, 29 Apr 2023 10:33:39 -0400 Subject: [PATCH 1/2] Sleep for 30 minutes --- src/itemsmanagerworker.cpp | 25 ++++++++++++++++++++----- src/itemsmanagerworker.h | 10 +++++++--- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/itemsmanagerworker.cpp b/src/itemsmanagerworker.cpp index cbf87e65f..9c2ea3002 100644 --- a/src/itemsmanagerworker.cpp +++ b/src/itemsmanagerworker.cpp @@ -727,6 +727,7 @@ void ItemsManagerWorker::OnTabReceived(int request_id) { ++requests_completed_; + if (!error) ++total_completed_; @@ -735,16 +736,30 @@ void ItemsManagerWorker::OnTabReceived(int request_id) { if (requests_completed_ == requests_needed_) { if (cancel_update_) { updating_ = false; - } else if (queue_.size() > 0) { + } + + else if (queue_.size() > 0) { + if (cached_requests_completed_ > 0) { // We basically don't want cached requests to count against throttle limit // so if we did get any cached requests fetch up to that number without a // large delay QTimer::singleShot(1, [&]() { FetchItems(cached_requests_completed_); }); - } else { - throttled = true; - QLOG_DEBUG() << "Sleeping one minute to prevent throttling."; - QTimer::singleShot(kThrottleSleep * 1000, this, SLOT(FetchItems())); + } + + else { + ++total_pre_throttle_; + + if(total_pre_throttle_ > maxThrottleRequests) { + QLOG_DEBUG() << "Sleeping thirty minutes to prevent throttling."; + total_pre_throttle_ = 0; + QTimer::singleShot(maxThrottleSleep * 1000, this, SLOT(FetchItems())); + } else { + throttled = true; + QLOG_DEBUG() << "Sleeping one minute to prevent throttling."; + QTimer::singleShot(kThrottleSleep * 1000, this, SLOT(FetchItems())); + } + } } } diff --git a/src/itemsmanagerworker.h b/src/itemsmanagerworker.h index 6a8d178a6..e035e62b0 100644 --- a/src/itemsmanagerworker.h +++ b/src/itemsmanagerworker.h @@ -36,8 +36,12 @@ class QTimer; class BuyoutManager; class TabCache; -const int kThrottleRequests = 45; +const int kThrottleRequests = 30; const int kThrottleSleep = 60; +const int maxThrottleRequests = 4; +const int maxThrottleSleep = 1900; +bool hitCap = false; + const int kMaxCacheSize = (1000*1024*1024); // 1GB struct ItemsRequest { @@ -68,7 +72,7 @@ public slots: void OnFirstTabReceived(); void OnTabReceived(int index); /* - * Makes 45 requests at once, should be called every minute. + * Makes 30 requests at once, should be called every minute. * These values are approximated (GGG throttles requests) * based on some quick testing. */ @@ -105,7 +109,7 @@ public slots: std::vector > tabs_signature_; bool cancel_update_{false}; Items items_; - int total_completed_, total_needed_, total_cached_; + int total_completed_, total_needed_, total_cached_, total_pre_throttle_; int requests_completed_, requests_needed_; int cached_requests_completed_{0}; From eea09c4d1fda0662e1ea08e9d3fed951937c9015 Mon Sep 17 00:00:00 2001 From: HaruhiSuzumiyah <68439343+HaruhiSuzumiyah@users.noreply.github.com> Date: Sat, 29 Apr 2023 15:03:26 -0400 Subject: [PATCH 2/2] whoops bool --- src/itemsmanagerworker.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/itemsmanagerworker.h b/src/itemsmanagerworker.h index e035e62b0..48cce9f78 100644 --- a/src/itemsmanagerworker.h +++ b/src/itemsmanagerworker.h @@ -40,7 +40,6 @@ const int kThrottleRequests = 30; const int kThrottleSleep = 60; const int maxThrottleRequests = 4; const int maxThrottleSleep = 1900; -bool hitCap = false; const int kMaxCacheSize = (1000*1024*1024); // 1GB