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

Set a custom API limit if specified in the config. #1043

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

thailyn
Copy link
Contributor

@thailyn thailyn commented Jun 22, 2019

The HttpTransport will only allow a positive limit that is no larger than the real API limit. A custom, smaller API limit will allow Procurement to play nicely with other applications that perform a known maximum number of API requests per minute.

@@ -55,7 +61,7 @@ public void StartTask()
}

RemvoeExpiredTasks();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appreciate it's not your typo, could you adjust please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. (I rewrote the class, so, ultimately, it is my typo. :) )

@@ -36,6 +36,12 @@ public TaskThrottle(TimeSpan windowSize, int windowLimit, int simultaneiousTasks
SimultaneiousTasksLimit = simultaneiousTasksLimit;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

if (Settings.UserSettings.Keys.Contains("ApiRequestLimit") &&
int.TryParse(Settings.UserSettings["ApiRequestLimit"], out customRequestLimit))
{
if (HttpTransport.AdjustThrottleWindowLimit(customRequestLimit))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change the message generation to a ternary please, more succinct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this?

@@ -36,6 +36,8 @@ protected enum HttpMethod { GET, POST }
private const string UpdateShopURL = @"https://www.pathofexile.com/forum/edit-thread/{0}";
private const string BumpShopURL = @"https://www.pathofexile.com/forum/post-reply/{0}";

private const int _maximumWindowLimit = 42;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be brought in as an application setting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather not, for two reasons.

  1. This value will likely very rarely -- if ever -- change, so the user will be unlikely to modify the setting. He can also easily make Procurement work very poorly by increasing the value.
  2. This class can't reference the Settings directly, since that would introduce a circular dependency between the projects. Thus -- barring more substantial refactoring I'm not interested in doing now -- it would then have to be set after the static constructor finishes, potentially after it started handling requests.


protected static TaskThrottle InitializeTaskThrottle()
{
return new TaskThrottle(TimeSpan.FromMinutes(1), _maximumWindowLimit, _maximumWindowLimit);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't tell just from the PR, isn't this just going to mindlessly overwrite the previously set task throttle?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would, if it were called again. As written, it is only ever invoked during HttpTransport's static constructor. It's also protected, so it can't be called by other classes, and HttpTransport itself doesn't call it. In any case, I changed it back to not call a function, so it is less ambiguous.

@Stickymaddness
Copy link
Member

I'll take a look at this, and the other outsanding PR's as soon as I can.

Thanks for the continued contributions and effort 👍

The HttpTransport will only allow a positive limit that is no larger
than the real API limit.  A custom, smaller API limit will allow
Procurement to play nicely with other applications that perform a known
maximum number of API requests per minute.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants