Merged request BucketId and ClientBucketId. Added IsClientBucket.

This commit is contained in:
RogueException
2016-11-14 08:04:40 -04:00
parent 2e95e4232f
commit 91e6cb98c3
3 changed files with 18 additions and 18 deletions

View File

@@ -172,8 +172,8 @@ namespace Discord.API
{ {
options = options ?? new RequestOptions(); options = options ?? new RequestOptions();
options.HeaderOnly = true; options.HeaderOnly = true;
options.BucketId = bucketId; options.BucketId = AuthTokenType == TokenType.User ? clientBucketId : bucketId;
options.ClientBucketId = AuthTokenType == TokenType.User ? clientBucketId : null; options.IsClientBucket = AuthTokenType == TokenType.User;
var request = new RestRequest(_restClient, method, endpoint, options); var request = new RestRequest(_restClient, method, endpoint, options);
await SendInternalAsync(method, endpoint, request).ConfigureAwait(false); await SendInternalAsync(method, endpoint, request).ConfigureAwait(false);
@@ -187,8 +187,8 @@ namespace Discord.API
{ {
options = options ?? new RequestOptions(); options = options ?? new RequestOptions();
options.HeaderOnly = true; options.HeaderOnly = true;
options.BucketId = bucketId; options.BucketId = AuthTokenType == TokenType.User ? clientBucketId : bucketId;
options.ClientBucketId = AuthTokenType == TokenType.User ? clientBucketId : null; options.IsClientBucket = AuthTokenType == TokenType.User;
var json = payload != null ? SerializeJson(payload) : null; var json = payload != null ? SerializeJson(payload) : null;
var request = new JsonRestRequest(_restClient, method, endpoint, json, options); var request = new JsonRestRequest(_restClient, method, endpoint, json, options);
@@ -203,8 +203,8 @@ namespace Discord.API
{ {
options = options ?? new RequestOptions(); options = options ?? new RequestOptions();
options.HeaderOnly = true; options.HeaderOnly = true;
options.BucketId = bucketId; options.BucketId = AuthTokenType == TokenType.User ? clientBucketId : bucketId;
options.ClientBucketId = AuthTokenType == TokenType.User ? clientBucketId : null; options.IsClientBucket = AuthTokenType == TokenType.User;
var request = new MultipartRestRequest(_restClient, method, endpoint, multipartArgs, options); var request = new MultipartRestRequest(_restClient, method, endpoint, multipartArgs, options);
await SendInternalAsync(method, endpoint, request).ConfigureAwait(false); await SendInternalAsync(method, endpoint, request).ConfigureAwait(false);
@@ -217,8 +217,8 @@ namespace Discord.API
string bucketId = null, string clientBucketId = null, RequestOptions options = null) where TResponse : class string bucketId = null, string clientBucketId = null, RequestOptions options = null) where TResponse : class
{ {
options = options ?? new RequestOptions(); options = options ?? new RequestOptions();
options.BucketId = bucketId; options.BucketId = AuthTokenType == TokenType.User ? clientBucketId : bucketId;
options.ClientBucketId = AuthTokenType == TokenType.User ? clientBucketId : null; options.IsClientBucket = AuthTokenType == TokenType.User;
var request = new RestRequest(_restClient, method, endpoint, options); var request = new RestRequest(_restClient, method, endpoint, options);
return DeserializeJson<TResponse>(await SendInternalAsync(method, endpoint, request).ConfigureAwait(false)); return DeserializeJson<TResponse>(await SendInternalAsync(method, endpoint, request).ConfigureAwait(false));
@@ -231,8 +231,8 @@ namespace Discord.API
string bucketId = null, string clientBucketId = null, RequestOptions options = null) where TResponse : class string bucketId = null, string clientBucketId = null, RequestOptions options = null) where TResponse : class
{ {
options = options ?? new RequestOptions(); options = options ?? new RequestOptions();
options.BucketId = bucketId; options.BucketId = AuthTokenType == TokenType.User ? clientBucketId : bucketId;
options.ClientBucketId = AuthTokenType == TokenType.User ? clientBucketId : null; options.IsClientBucket = AuthTokenType == TokenType.User;
var json = payload != null ? SerializeJson(payload) : null; var json = payload != null ? SerializeJson(payload) : null;
var request = new JsonRestRequest(_restClient, method, endpoint, json, options); var request = new JsonRestRequest(_restClient, method, endpoint, json, options);
@@ -246,8 +246,8 @@ namespace Discord.API
string bucketId = null, string clientBucketId = null, RequestOptions options = null) string bucketId = null, string clientBucketId = null, RequestOptions options = null)
{ {
options = options ?? new RequestOptions(); options = options ?? new RequestOptions();
options.BucketId = bucketId; options.BucketId = AuthTokenType == TokenType.User ? clientBucketId : bucketId;
options.ClientBucketId = AuthTokenType == TokenType.User ? clientBucketId : null; options.IsClientBucket = AuthTokenType == TokenType.User;
var request = new MultipartRestRequest(_restClient, method, endpoint, multipartArgs, options); var request = new MultipartRestRequest(_restClient, method, endpoint, multipartArgs, options);
return DeserializeJson<TResponse>(await SendInternalAsync(method, endpoint, request).ConfigureAwait(false)); return DeserializeJson<TResponse>(await SendInternalAsync(method, endpoint, request).ConfigureAwait(false));

View File

@@ -29,8 +29,8 @@ namespace Discord.Net.Queue
_lock = new object(); _lock = new object();
if (request.Options.ClientBucketId != null) if (request.Options.IsClientBucket)
WindowCount = ClientBucket.Get(request.Options.ClientBucketId).WindowCount; WindowCount = ClientBucket.Get(request.Options.BucketId).WindowCount;
else else
WindowCount = 1; //Only allow one request until we get a header back WindowCount = 1; //Only allow one request until we get a header back
_semaphore = WindowCount; _semaphore = WindowCount;
@@ -218,11 +218,11 @@ namespace Discord.Net.Queue
Debug.WriteLine($"[{id}] X-RateLimit-Reset: {info.Reset.Value.ToUnixTimeSeconds()} ({diff} ms, {lag.TotalMilliseconds} ms lag)"); Debug.WriteLine($"[{id}] X-RateLimit-Reset: {info.Reset.Value.ToUnixTimeSeconds()} ({diff} ms, {lag.TotalMilliseconds} ms lag)");
#endif #endif
} }
else if (request.Options.ClientBucketId != null) else if (request.Options.IsClientBucket && request.Options.BucketId != null)
{ {
resetTick = DateTimeOffset.UtcNow.AddSeconds(ClientBucket.Get(request.Options.ClientBucketId).WindowSeconds); resetTick = DateTimeOffset.UtcNow.AddSeconds(ClientBucket.Get(request.Options.BucketId).WindowSeconds);
#if DEBUG_LIMITS #if DEBUG_LIMITS
Debug.WriteLine($"[{id}] Client Bucket ({ClientBucket.Get(request.Options.ClientBucketId).WindowSeconds * 1000} ms)"); Debug.WriteLine($"[{id}] Client Bucket ({ClientBucket.Get(request.Options.BucketId).WindowSeconds * 1000} ms)");
#endif #endif
} }

View File

@@ -10,7 +10,7 @@
internal bool IgnoreState { get; set; } internal bool IgnoreState { get; set; }
internal string BucketId { get; set; } internal string BucketId { get; set; }
internal string ClientBucketId { get; set; } internal bool IsClientBucket { get; set; }
internal static RequestOptions CreateOrClone(RequestOptions options) internal static RequestOptions CreateOrClone(RequestOptions options)
{ {