From ece874db0b8256b8acd3bd448b4af010169a1380 Mon Sep 17 00:00:00 2001 From: BovineOx <73857041+BovineOx@users.noreply.github.com> Date: Mon, 13 Nov 2023 14:53:31 +0000 Subject: [PATCH] Hotfix to tolerate server branch limits of 100 and 500 (#3039) Hooked StreamGetBranches for retry if 500 limit fails We are catching the SpeckleGraphQLException exception as a way to see that the call to get up to 500 stream branches failed. We can then retry with 100. While the exception isn't as specific as we would like, it is probably good enough and we don't have anything else to go on, based on how the GQL library is constructed. --- .../Client.BranchOperations.cs | 22 +++++++++++++++++++ Core/Core/Api/GraphQL/Client.cs | 2 +- .../ViewModels/StreamSelectorViewModel.cs | 2 +- .../DesktopUI2/ViewModels/StreamViewModel.cs | 5 +++-- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.BranchOperations.cs b/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.BranchOperations.cs index 386cccdfcd..7e4c8e0b13 100644 --- a/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.BranchOperations.cs +++ b/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.BranchOperations.cs @@ -10,6 +10,28 @@ namespace Speckle.Core.Api; public partial class Client { + /// + /// Get branches from a given stream, first with a max of 500 and then with a max of 100. + /// This ensures that if the server API is limiting to 100 branches, that any failure will try again at the lower value. + /// + /// Id of the stream to get the branches from + /// Max number of commits to retrieve + /// + public async Task> StreamGetBranchesWithLimitRetry(string streamId, int commitsLimit = 10) + { + List? branches = null; + try + { + branches = await StreamGetBranches(streamId, 500, commitsLimit).ConfigureAwait(true); + } + catch (SpeckleGraphQLException) + { + branches = await StreamGetBranches(streamId, 100, commitsLimit).ConfigureAwait(true); + } + + return branches; + } + /// /// Get branches from a given stream /// diff --git a/Core/Core/Api/GraphQL/Client.cs b/Core/Core/Api/GraphQL/Client.cs index 26f6da51f9..10c8640287 100644 --- a/Core/Core/Api/GraphQL/Client.cs +++ b/Core/Core/Api/GraphQL/Client.cs @@ -155,7 +155,7 @@ internal async Task ExecuteGraphQLRequest(GraphQLRequest request, Cancella { var result = await ExecuteWithResiliencePolicies(async () => { - var result = await GQLClient.SendMutationAsync(request, cancellationToken).ConfigureAwait(false); + GraphQLResponse result = await GQLClient.SendMutationAsync(request, cancellationToken).ConfigureAwait(false); MaybeThrowFromGraphQLErrors(request, result); return result.Data; }) diff --git a/DesktopUI2/DesktopUI2/ViewModels/StreamSelectorViewModel.cs b/DesktopUI2/DesktopUI2/ViewModels/StreamSelectorViewModel.cs index 02857de481..39cbb6f6ca 100644 --- a/DesktopUI2/DesktopUI2/ViewModels/StreamSelectorViewModel.cs +++ b/DesktopUI2/DesktopUI2/ViewModels/StreamSelectorViewModel.cs @@ -98,7 +98,7 @@ private async void GetBranches() { using var client = new Client(SelectedStream.Account); - Branches = (await client.StreamGetBranches(SelectedStream.Stream.id, 100, 1).ConfigureAwait(true)) + Branches = (await client.StreamGetBranchesWithLimitRetry(SelectedStream.Stream.id, 1).ConfigureAwait(true)) .Where(x => x.commits.totalCount > 0) .ToList(); diff --git a/DesktopUI2/DesktopUI2/ViewModels/StreamViewModel.cs b/DesktopUI2/DesktopUI2/ViewModels/StreamViewModel.cs index e2edd24687..d52a735b38 100644 --- a/DesktopUI2/DesktopUI2/ViewModels/StreamViewModel.cs +++ b/DesktopUI2/DesktopUI2/ViewModels/StreamViewModel.cs @@ -23,6 +23,7 @@ using DesktopUI2.Views.Pages; using DesktopUI2.Views.Windows.Dialogs; using DynamicData; +using GraphQL; using Material.Dialog.Icons; using Material.Icons; using Material.Icons.Avalonia; @@ -249,7 +250,7 @@ internal async void GetBranchesAndRestoreState() AvailableFilters = new List(Bindings.GetSelectionFilters().Select(x => new FilterViewModel(x))); SelectedFilter = AvailableFilters[0]; - Branches = await Client.StreamGetBranches(Stream.id, 100, 0).ConfigureAwait(true); + Branches = await Client.StreamGetBranchesWithLimitRetry(Stream.id, 0).ConfigureAwait(true); var index = Branches.FindIndex(x => x.name == StreamState.BranchName); if (index != -1) @@ -417,7 +418,7 @@ private async Task GetBranches() try { var prevBranchName = SelectedBranch != null ? SelectedBranch.Branch.name : StreamState.BranchName; - Branches = await Client.StreamGetBranches(Stream.id, 500, 0).ConfigureAwait(true); + Branches = await Client.StreamGetBranchesWithLimitRetry(Stream.id, 0).ConfigureAwait(true); var index = Branches.FindIndex(x => x.name == prevBranchName); if (index != -1)