Skip to content

Commit

Permalink
Improve handling of global rate-limit (#2465)
Browse files Browse the repository at this point in the history
  • Loading branch information
MinnDevelopment committed May 11, 2023
1 parent d1b06b6 commit ad66a69
Showing 1 changed file with 17 additions and 5 deletions.
Expand Up @@ -387,20 +387,16 @@ public long getRateLimit()
long now = getNow();

long global = getGlobalRateLimit(now);
// Global rate limit is more important to handle
if (global > 0)
return global;

// Check if the bucket reset time has expired
if (reset <= now)
{
// Update the remaining uses to the limit (we don't know better)
remaining = 1;
return 0L;
}

// If there are remaining requests we don't need to do anything, otherwise return backoff in milliseconds
return remaining < 1 ? reset - now : 0L;
return Math.max(global, remaining < 1 ? reset - now : 0L);
}

protected boolean isGlobalRateLimit()
Expand Down Expand Up @@ -502,6 +498,22 @@ public String toString()
{
return bucketId;
}

@Override
public int hashCode()
{
return bucketId.hashCode();
}

@Override
public boolean equals(Object obj)
{
if (obj == this)
return true;
if (!(obj instanceof Bucket))
return false;
return this.bucketId.equals(((Bucket) obj).bucketId);
}
}

private class ClassicBucket extends Bucket
Expand Down

0 comments on commit ad66a69

Please sign in to comment.