Skip to content

Commit

Permalink
fix(core): Fixes Branch get Limit up to 500 (#3036)
Browse files Browse the repository at this point in the history
* fix(dui): Bumps branch limit to 500 everywhere it's needed in DUI

* feat: Created `ServerLimits` static class

* test(core): Added unit tests for branch limits

* fix: Branch limit integration tests.

* fix: Lower parallelism and add env var to server config

* fix: Removes env var from compose file

* Revert "fix: Removes env var from compose file"

This reverts commit 8f3dca7.
  • Loading branch information
AlanRynne authored Nov 10, 2023
1 parent bdf0ebe commit ba70c5c
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 4 deletions.
13 changes: 13 additions & 0 deletions Core/Core/Api/ServerLimits.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Speckle.Core.Api;

/// <summary>
/// Defines the limits for specific API calls on the Speckle Server.
/// These are magic numbers! Should be aligned with server always.
/// </summary>
/// <remarks>
/// ⚠️ Not all limits are reflected here!
/// </remarks>
public static class ServerLimits
{
public const int BRANCH_GET_LIMIT = 500;
}
49 changes: 48 additions & 1 deletion Core/IntegrationTests/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ public async Task IsStreamAccessible()
Assert.True(res);
}


[Test, Order(13)]
public async Task StreamSearch()
{
Expand Down Expand Up @@ -275,6 +274,54 @@ public async Task StreamGetBranches()
Assert.That(res[0].name, Is.EqualTo("main"));
}

[Test, Order(51)]
public async Task StreamGetBranches_Throws_WhenRequestingOverLimit()
{
Assert.ThrowsAsync<SpeckleGraphQLException<StreamData>>(
async () => await myClient.StreamGetBranches(streamId, ServerLimits.BRANCH_GET_LIMIT + 1).ConfigureAwait(false)
);
var res = await myClient.StreamGetBranches(streamId, ServerLimits.BRANCH_GET_LIMIT).ConfigureAwait(false);

Assert.That(res, Is.Not.Null);
}

[Test, Order(52)]
public async Task StreamGetBranches_WithManyBranches()
{
var newStreamId = await myClient.StreamCreate(new StreamCreateInput { name = "Many branches stream" });

await CreateEmptyBranches(myClient, newStreamId, ServerLimits.BRANCH_GET_LIMIT);

var res = await myClient.StreamGetBranches(newStreamId, ServerLimits.BRANCH_GET_LIMIT);

Assert.That(res, Is.Not.Null);
Assert.That(res, Has.Count.EqualTo(ServerLimits.BRANCH_GET_LIMIT));
}

public async Task CreateEmptyBranches(
Client client,
string streamId,
int branchCount,
string branchPrefix = "Test branch"
)
{
// now let's send HTTP requests to each of these URLs in parallel
var options = new ParallelOptions { MaxDegreeOfParallelism = 2 };

// now let's send HTTP requests to each of these URLs in parallel
await Parallel.ForEachAsync(
Enumerable.Range(0, branchCount),
options,
async (i, cancellationToken) =>
{
await client.BranchCreate(
new BranchCreateInput { name = $"{branchPrefix} {i}", streamId = streamId },
cancellationToken
);
}
);
}

#region commit

[Test, Order(43)]
Expand Down
1 change: 1 addition & 0 deletions Core/IntegrationTests/TestsIntegration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<NoWarn>$(NoWarn);CA2007</NoWarn>
</PropertyGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute" />
Expand Down
1 change: 1 addition & 0 deletions Core/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ services:
S3_CREATE_BUCKET: "true"

FILE_SIZE_LIMIT_MB: 100
MAX_PROJECT_MODELS_PER_PAGE: 500

# TODO: Change this to a unique secret for this server
SESSION_SECRET: "TODO:ReplaceWithLongString"
Expand Down
4 changes: 3 additions & 1 deletion DesktopUI2/DesktopUI2/ViewModels/StreamSelectorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ 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.StreamGetBranches(SelectedStream.Stream.id, ServerLimits.BRANCH_GET_LIMIT, 1).ConfigureAwait(true)
)
.Where(x => x.commits.totalCount > 0)
.ToList();

Expand Down
4 changes: 2 additions & 2 deletions DesktopUI2/DesktopUI2/ViewModels/StreamViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,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.StreamGetBranches(Stream.id, ServerLimits.BRANCH_GET_LIMIT, 0).ConfigureAwait(true);

//TODO: Core's API calls and the StreamWrapper class need to be updated to properly support FE2 links
//this is a temporary workaround
Expand Down Expand Up @@ -430,7 +430,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.StreamGetBranches(Stream.id, ServerLimits.BRANCH_GET_LIMIT, 0).ConfigureAwait(true);

var index = Branches.FindIndex(x => x.name == prevBranchName);
if (index != -1)
Expand Down

0 comments on commit ba70c5c

Please sign in to comment.