Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sleep for 30 minutes after 3 failed requests #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/itemsmanagerworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ void ItemsManagerWorker::OnTabReceived(int request_id) {

++requests_completed_;


if (!error)
++total_completed_;

Expand All @@ -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()));
}

}
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/itemsmanagerworker.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ 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;

const int kMaxCacheSize = (1000*1024*1024); // 1GB

struct ItemsRequest {
Expand Down Expand Up @@ -68,7 +71,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.
*/
Expand Down Expand Up @@ -105,7 +108,7 @@ public slots:
std::vector<std::pair<std::string, std::string> > 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};

Expand Down