diff --git a/Hayden/Api/NetworkPolicies.cs b/Hayden/Api/NetworkPolicies.cs index 3d283ab..44e1d35 100644 --- a/Hayden/Api/NetworkPolicies.cs +++ b/Hayden/Api/NetworkPolicies.cs @@ -28,7 +28,7 @@ public static class NetworkPolicies + TimeSpan.FromMilliseconds(random.Next(0, 5000)) // plus some jitter: up to 5 seconds ) .WrapAsync( - Policy.TimeoutAsync(10, TimeoutStrategy.Pessimistic, async (context, span, failedTask) => + Policy.TimeoutAsync(10, TimeoutStrategy.Optimistic, async (context, span, failedTask) => { Program.Log($"Timeout occurred: {context.OperationKey}", true); }) @@ -48,7 +48,7 @@ public static AsyncPolicy GenericRetryPolicy(int tries) + TimeSpan.FromMilliseconds(random.Next(0, 5000)) // plus some jitter: up to 5 seconds ) .WrapAsync( - Policy.TimeoutAsync(10, TimeoutStrategy.Pessimistic, async (context, span, failedTask) => + Policy.TimeoutAsync(10, TimeoutStrategy.Optimistic, async (context, span, failedTask) => { Program.Log($"Timeout occurred: {context.OperationKey}", true); }) diff --git a/Hayden/Api/YotsubaApi.cs b/Hayden/Api/YotsubaApi.cs index 6a4a346..2ab80c8 100644 --- a/Hayden/Api/YotsubaApi.cs +++ b/Hayden/Api/YotsubaApi.cs @@ -7,6 +7,7 @@ using Hayden.Api; using Hayden.Models; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using Polly; using Thread = Hayden.Models.Thread; @@ -78,9 +79,6 @@ private static async Task DoCall(Uri uri, HttpClient client return await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken); } - // For performance, we keep a single static instance of a JsonSerializer object instead of recreating it multiple times. - private static readonly JsonSerializer jsonSerializer = JsonSerializer.Create(); - private static async Task> MakeYotsubaApiCall(Uri uri, HttpClient client, DateTimeOffset? modifiedSince = null, CancellationToken cancellationToken = default) { int callCount = 0; @@ -103,7 +101,7 @@ private static async Task> MakeYotsubaApiCall(Uri uri, HttpCli using StreamReader streamReader = new StreamReader(responseStream); using JsonReader reader = new JsonTextReader(streamReader); - var obj = jsonSerializer.Deserialize(reader); + var obj = (await JToken.LoadAsync(reader, cancellationToken)).ToObject(); return new ApiResponse(ResponseType.Ok, obj); }