Skip to content

Commit

Permalink
Hotfix to tolerate server branch limits of 100 and 500 (#3039)
Browse files Browse the repository at this point in the history
Hooked StreamGetBranches for retry if 500 limit fails

We are catching the SpeckleGraphQLException<StreamData> 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.
  • Loading branch information
BovineOx authored Nov 13, 2023
1 parent 348fe44 commit ece874d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@ namespace Speckle.Core.Api;

public partial class Client
{
/// <summary>
/// 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.
/// </summary>
/// <param name="streamId">Id of the stream to get the branches from</param>
/// <param name="commitsLimit">Max number of commits to retrieve</param>
/// <returns></returns>
public async Task<List<Branch>> StreamGetBranchesWithLimitRetry(string streamId, int commitsLimit = 10)
{
List<Branch>? branches = null;
try
{
branches = await StreamGetBranches(streamId, 500, commitsLimit).ConfigureAwait(true);
}
catch (SpeckleGraphQLException<StreamData>)
{
branches = await StreamGetBranches(streamId, 100, commitsLimit).ConfigureAwait(true);
}

return branches;
}

/// <summary>
/// Get branches from a given stream
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Core/Core/Api/GraphQL/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ internal async Task<T> ExecuteGraphQLRequest<T>(GraphQLRequest request, Cancella
{
var result = await ExecuteWithResiliencePolicies(async () =>
{
var result = await GQLClient.SendMutationAsync<T>(request, cancellationToken).ConfigureAwait(false);
GraphQLResponse<T> result = await GQLClient.SendMutationAsync<T>(request, cancellationToken).ConfigureAwait(false);
MaybeThrowFromGraphQLErrors(request, result);
return result.Data;
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
5 changes: 3 additions & 2 deletions DesktopUI2/DesktopUI2/ViewModels/StreamViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -249,7 +250,7 @@ internal async void GetBranchesAndRestoreState()
AvailableFilters = new List<FilterViewModel>(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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ece874d

Please sign in to comment.