From 91e6cb98c3ae8c3e6e382773a154ebd6f0dc5d9d Mon Sep 17 00:00:00 2001 From: RogueException Date: Mon, 14 Nov 2016 08:04:40 -0400 Subject: [PATCH] Merged request BucketId and ClientBucketId. Added IsClientBucket. --- .../API/DiscordRestApiClient.cs | 24 +++++++++---------- .../Net/Queue/RequestQueueBucket.cs | 10 ++++---- src/Discord.Net.Core/RequestOptions.cs | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Discord.Net.Core/API/DiscordRestApiClient.cs b/src/Discord.Net.Core/API/DiscordRestApiClient.cs index 966cdd83a..553cbd1c3 100644 --- a/src/Discord.Net.Core/API/DiscordRestApiClient.cs +++ b/src/Discord.Net.Core/API/DiscordRestApiClient.cs @@ -172,8 +172,8 @@ namespace Discord.API { options = options ?? new RequestOptions(); options.HeaderOnly = true; - options.BucketId = bucketId; - options.ClientBucketId = AuthTokenType == TokenType.User ? clientBucketId : null; + options.BucketId = AuthTokenType == TokenType.User ? clientBucketId : bucketId; + options.IsClientBucket = AuthTokenType == TokenType.User; var request = new RestRequest(_restClient, method, endpoint, options); await SendInternalAsync(method, endpoint, request).ConfigureAwait(false); @@ -187,8 +187,8 @@ namespace Discord.API { options = options ?? new RequestOptions(); options.HeaderOnly = true; - options.BucketId = bucketId; - options.ClientBucketId = AuthTokenType == TokenType.User ? clientBucketId : null; + options.BucketId = AuthTokenType == TokenType.User ? clientBucketId : bucketId; + options.IsClientBucket = AuthTokenType == TokenType.User; var json = payload != null ? SerializeJson(payload) : null; var request = new JsonRestRequest(_restClient, method, endpoint, json, options); @@ -203,8 +203,8 @@ namespace Discord.API { options = options ?? new RequestOptions(); options.HeaderOnly = true; - options.BucketId = bucketId; - options.ClientBucketId = AuthTokenType == TokenType.User ? clientBucketId : null; + options.BucketId = AuthTokenType == TokenType.User ? clientBucketId : bucketId; + options.IsClientBucket = AuthTokenType == TokenType.User; var request = new MultipartRestRequest(_restClient, method, endpoint, multipartArgs, options); 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 { options = options ?? new RequestOptions(); - options.BucketId = bucketId; - options.ClientBucketId = AuthTokenType == TokenType.User ? clientBucketId : null; + options.BucketId = AuthTokenType == TokenType.User ? clientBucketId : bucketId; + options.IsClientBucket = AuthTokenType == TokenType.User; var request = new RestRequest(_restClient, method, endpoint, options); return DeserializeJson(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 { options = options ?? new RequestOptions(); - options.BucketId = bucketId; - options.ClientBucketId = AuthTokenType == TokenType.User ? clientBucketId : null; + options.BucketId = AuthTokenType == TokenType.User ? clientBucketId : bucketId; + options.IsClientBucket = AuthTokenType == TokenType.User; var json = payload != null ? SerializeJson(payload) : null; 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) { options = options ?? new RequestOptions(); - options.BucketId = bucketId; - options.ClientBucketId = AuthTokenType == TokenType.User ? clientBucketId : null; + options.BucketId = AuthTokenType == TokenType.User ? clientBucketId : bucketId; + options.IsClientBucket = AuthTokenType == TokenType.User; var request = new MultipartRestRequest(_restClient, method, endpoint, multipartArgs, options); return DeserializeJson(await SendInternalAsync(method, endpoint, request).ConfigureAwait(false)); diff --git a/src/Discord.Net.Core/Net/Queue/RequestQueueBucket.cs b/src/Discord.Net.Core/Net/Queue/RequestQueueBucket.cs index 59fbe51af..19976e998 100644 --- a/src/Discord.Net.Core/Net/Queue/RequestQueueBucket.cs +++ b/src/Discord.Net.Core/Net/Queue/RequestQueueBucket.cs @@ -29,8 +29,8 @@ namespace Discord.Net.Queue _lock = new object(); - if (request.Options.ClientBucketId != null) - WindowCount = ClientBucket.Get(request.Options.ClientBucketId).WindowCount; + if (request.Options.IsClientBucket) + WindowCount = ClientBucket.Get(request.Options.BucketId).WindowCount; else WindowCount = 1; //Only allow one request until we get a header back _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)"); #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 - 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 } diff --git a/src/Discord.Net.Core/RequestOptions.cs b/src/Discord.Net.Core/RequestOptions.cs index 3af6c929d..195390ecf 100644 --- a/src/Discord.Net.Core/RequestOptions.cs +++ b/src/Discord.Net.Core/RequestOptions.cs @@ -10,7 +10,7 @@ internal bool IgnoreState { get; set; } internal string BucketId { get; set; } - internal string ClientBucketId { get; set; } + internal bool IsClientBucket { get; set; } internal static RequestOptions CreateOrClone(RequestOptions options) {