Skip to content

Commit

Permalink
Limit FE1 API usage to essentials (#3662)
Browse files Browse the repository at this point in the history
* Updated DUI2

* remove comment subscription

* Comments

* fix comment

* VersionUpdate subscription workaround

* Dynamo

* Fixed issue with collections being modified while enumerating

* removed deprecated tests

* Marked deprecated true on all legacy subscriptions

* using directives
  • Loading branch information
JR-Morgan authored Dec 12, 2024
1 parent a0e7496 commit 2861ade
Show file tree
Hide file tree
Showing 33 changed files with 426 additions and 728 deletions.
18 changes: 12 additions & 6 deletions ConnectorDynamo/ConnectorDynamo/ReceiveNode/Receive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
using ProtoCore.AST.AssociativeAST;
using Speckle.ConnectorDynamo.Functions;
using Speckle.Core.Api;
using Speckle.Core.Api.SubscriptionModels;
using Speckle.Core.Api.GraphQL.Enums;
using Speckle.Core.Api.GraphQL.Models;
using Speckle.Core.Credentials;
using Speckle.Core.Logging;
using Speckle.Core.Models.Extensions;
Expand Down Expand Up @@ -456,8 +457,7 @@ internal void InitializeReceiver()
{
var account = Stream.GetAccount().Result;
Client = new Client(account);
Client.SubscribeCommitCreated(Stream.StreamId);
Client.OnCommitCreated += OnCommitChange;
Client.Subscription.CreateProjectVersionsUpdatedSubscription(Stream.StreamId).Listeners += OnVersionChange;

CheckIfBehind();
}
Expand Down Expand Up @@ -597,14 +597,20 @@ protected virtual void RequestNewInputs()
OnInputsChanged?.Invoke();
}

private void OnCommitChange(object sender, CommitInfo e)
private void OnVersionChange(object sender, ProjectVersionsUpdatedMessage e)
{
if (e.branchName != (Stream.BranchName ?? "main"))
if (e.type != ProjectVersionsUpdatedMessageType.CREATED)
{
return;
}

Task.Run(async () => GetExpiredObjectCount(e.objectId));
var isSameBranch = e.version.model.name == (Stream.BranchName ?? "main") || e.version.model.id == Stream.BranchName;
if (!isSameBranch)
{
return;
}

Task.Run(async () => GetExpiredObjectCount(e.version.referencedObject));
if (AutoUpdate)
{
OnNewDataAvail?.Invoke();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
using Grasshopper.Kernel.Types;
using Rhino;
using Speckle.Core.Api;
using Speckle.Core.Api.SubscriptionModels;
using Speckle.Core.Api.GraphQL.Enums;
using Speckle.Core.Api.GraphQL.Models;
using Speckle.Core.Credentials;
using Speckle.Core.Logging;
using Speckle.Core.Models;
Expand Down Expand Up @@ -112,14 +113,19 @@ private async Task ResetApiClient(StreamWrapper wrapper)
ApiClient?.Dispose();
var acc = await wrapper.GetAccount();
ApiClient = new Client(acc);
ApiClient.SubscribeCommitCreated(StreamWrapper.StreamId);
ApiClient.OnCommitCreated += ApiClient_OnCommitCreated;
ApiClient.Subscription.CreateProjectVersionsUpdatedSubscription(StreamWrapper.StreamId).Listeners +=
ApiClient_OnVersionUpdate;
}

private void ApiClient_OnCommitCreated(object sender, CommitInfo e)
private void ApiClient_OnVersionUpdate(object sender, ProjectVersionsUpdatedMessage e)
{
// Break if wrapper is branch type and branch name is not equal.
if (StreamWrapper.Type == StreamWrapperType.Branch && e.branchName != StreamWrapper.BranchName)
if (StreamWrapper.Type == StreamWrapperType.Branch && e.modelId != StreamWrapper.BranchName)
{
return;
}

if (e.type != ProjectVersionsUpdatedMessageType.CREATED)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
using GrasshopperAsyncComponent;
using Rhino;
using Speckle.Core.Api;
using Speckle.Core.Api.SubscriptionModels;
using Speckle.Core.Api.GraphQL.Enums;
using Speckle.Core.Api.GraphQL.Models;
using Speckle.Core.Credentials;
using Speckle.Core.Helpers;
using Speckle.Core.Logging;
Expand Down Expand Up @@ -577,8 +578,8 @@ public async Task ResetApiClient(StreamWrapper wrapper)

ApiClient?.Dispose();
ApiClient = new Client(account);
ApiClient.SubscribeCommitCreated(StreamWrapper.StreamId);
ApiClient.OnCommitCreated += ApiClient_OnCommitCreated;
ApiClient.Subscription.CreateProjectVersionsUpdatedSubscription(StreamWrapper.StreamId).Listeners +=
ApiClient_OnVersionUpdate;
}
catch (Exception e) when (!e.IsFatal())
{
Expand All @@ -587,10 +588,18 @@ public async Task ResetApiClient(StreamWrapper wrapper)
}
}

private void ApiClient_OnCommitCreated(object sender, CommitInfo e)
private void ApiClient_OnVersionUpdate(object sender, ProjectVersionsUpdatedMessage e)
{
if (e.type != ProjectVersionsUpdatedMessageType.CREATED)
{
return;
}

// Break if wrapper is branch type and branch name is not equal.
if (StreamWrapper.Type == StreamWrapperType.Branch && e.branchName != StreamWrapper.BranchName)
bool isCurrentBranch =
StreamWrapper.Type == StreamWrapperType.Branch
&& (e.version?.model.name == StreamWrapper.BranchName || e.version?.model.id == StreamWrapper.BranchName);
if (!isCurrentBranch)
{
return;
}
Expand Down
1 change: 0 additions & 1 deletion ConnectorRevit/RevitSharedResources/Helpers/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public partial class Client
/// <param name="limit">Max number of activity items to get</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[Obsolete("Activity is no longer supported", true)]
public async Task<List<ActivityItem>> StreamGetActivity(
string id,
DateTime? after = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public partial class Client
/// <param name="cancellationToken"></param>
/// <returns></returns>
/// <seealso cref="CommentResource.GetProjectComments"/>
[Obsolete($"Use client.{nameof(CommentResource)}.{nameof(CommentResource.GetProjectComments)}")]
[Obsolete($"Use client.{nameof(CommentResource)}.{nameof(CommentResource.GetProjectComments)}", true)]
public async Task<Comments> StreamGetComments(
string streamId,
int limit = 25,
Expand Down Expand Up @@ -83,7 +83,7 @@ public async Task<Comments> StreamGetComments(
/// <param name="cancellationToken"></param>
/// <returns></returns>
/// <seealso cref="CommentResource.GetProjectComments"/>
[Obsolete($"Use client.{nameof(CommentResource)}.{nameof(CommentResource.GetProjectComments)}")]
[Obsolete($"Use client.{nameof(CommentResource)}.{nameof(CommentResource.GetProjectComments)}", true)]
public async Task<string> StreamGetCommentScreenshot(
string id,
string streamId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,16 @@ public async Task<List<Stream>> StreamsGet(int limit = 10, CancellationToken can
return res.activeUser.streams.items;
}

//TODO: API GAP
/// <summary>
/// Gets all favorite streams for the current user
/// </summary>
/// <param name="limit">Max number of streams to return</param>
/// <param name="cancellationToken"></param>
/// <remarks>
/// Favourite streams is no longer a feature
/// </remarks>
/// <returns></returns>
[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE, true)]
public async Task<List<Stream>> FavoriteStreamsGet(int limit = 10, CancellationToken cancellationToken = default)
{
var request = new GraphQLRequest
Expand Down Expand Up @@ -328,6 +331,7 @@ public async Task<bool> StreamDelete(string id, CancellationToken cancellationTo
/// <param name="permissionInput"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[Obsolete($"Use client.{nameof(Project)}.{nameof(ProjectResource.UpdateRole)}", true)]
public async Task<bool> StreamRevokePermission(
StreamRevokePermissionInput permissionInput,
CancellationToken cancellationToken = default
Expand All @@ -354,7 +358,7 @@ public async Task<bool> StreamRevokePermission(
/// <returns></returns>
/// <exception cref="SpeckleException"></exception>
/// <seealso cref="GraphQL.Resources.ProjectResource.UpdateRole"/>
[Obsolete($"Use client.{nameof(Project)}.{nameof(ProjectResource.UpdateRole)}")]
[Obsolete($"Use client.{nameof(Project)}.{nameof(ProjectResource.UpdateRole)}", true)]
public async Task<bool> StreamUpdatePermission(
StreamPermissionInput updatePermissionInput,
CancellationToken cancellationToken = default
Expand Down Expand Up @@ -418,7 +422,7 @@ public async Task<Stream> StreamGetPendingCollaborators(
/// <param name="cancellationToken"></param>
/// <returns></returns>
/// <seealso cref="GraphQL.Resources.ProjectInviteResource.Create"/>
[Obsolete($"Use client.{nameof(ProjectInvite)}.{nameof(ProjectInviteResource.Create)}")]
[Obsolete($"Use client.{nameof(ProjectInvite)}.{nameof(ProjectInviteResource.Create)}", true)]
public async Task<bool> StreamInviteCreate(
StreamInviteCreateInput inviteCreateInput,
CancellationToken cancellationToken = default
Expand Down Expand Up @@ -451,7 +455,7 @@ mutation streamInviteCreate($input: StreamInviteCreateInput!) {
/// <param name="cancellationToken"></param>
/// <returns></returns>
/// <seealso cref="GraphQL.Resources.ProjectInviteResource.Cancel"/>
[Obsolete($"Use client.{nameof(ProjectInvite)}.{nameof(ProjectInviteResource.Cancel)}")]
[Obsolete($"Use client.{nameof(ProjectInvite)}.{nameof(ProjectInviteResource.Cancel)}", true)]
public async Task<bool> StreamInviteCancel(
string streamId,
string inviteId,
Expand Down Expand Up @@ -482,7 +486,7 @@ mutation streamInviteCancel( $streamId: String!, $inviteId: String! ) {
/// <returns></returns>
/// <exception cref="SpeckleException"></exception>
/// <seealso cref="GraphQL.Resources.ProjectInviteResource.Use"/>
[Obsolete($"Use client.{nameof(ProjectInvite)}.{nameof(ProjectInviteResource.Use)}")]
[Obsolete($"Use client.{nameof(ProjectInvite)}.{nameof(ProjectInviteResource.Use)}", true)]
public async Task<bool> StreamInviteUse(
string streamId,
string token,
Expand Down Expand Up @@ -515,7 +519,7 @@ mutation streamInviteUse( $accept: Boolean!, $streamId: String!, $token: String!
/// <param name="cancellationToken"></param>
/// <returns></returns>
/// <seealso cref="GraphQL.Resources.ProjectInviteResource.Use"/>
[Obsolete($"Use client.{nameof(ActiveUser)}.{nameof(ActiveUserResource.ProjectInvites)}")]
[Obsolete($"Use client.{nameof(ActiveUser)}.{nameof(ActiveUserResource.ProjectInvites)}", true)]
public async Task<List<PendingStreamCollaborator>> GetAllPendingInvites(CancellationToken cancellationToken = default)
{
var request = new GraphQLRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ public partial class Client
{
#region BranchCreated

[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE, true)]
public delegate void BranchCreatedHandler(object sender, BranchInfo e);

[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE, true)]
public event BranchCreatedHandler OnBranchCreated;

[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE)]
public IDisposable BranchCreatedSubscription { get; private set; }

/// <summary>
/// Subscribe to events of branch created for a stream
/// </summary>
/// <returns></returns>
[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE, true)]
public void SubscribeBranchCreated(string streamId)
{
var request = new GraphQLRequest { Query = $@"subscription {{ branchCreated (streamId: ""{streamId}"") }}" };
Expand All @@ -28,22 +33,27 @@ public void SubscribeBranchCreated(string streamId)
);
}

[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE, true)]
public bool HasSubscribedBranchCreated => BranchCreatedSubscription != null;

#endregion


#region BranchUpdated

[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE, true)]
public delegate void BranchUpdatedHandler(object sender, BranchInfo e);

[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE, true)]
public event BranchUpdatedHandler OnBranchUpdated;

[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE)]
public IDisposable BranchUpdatedSubscription { get; private set; }

/// <summary>
/// Subscribe to events of branch updated for a stream
/// </summary>
/// <returns></returns>
[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE)]
public void SubscribeBranchUpdated(string streamId, string branchId = null)
{
var request = new GraphQLRequest
Expand All @@ -56,21 +66,26 @@ public void SubscribeBranchUpdated(string streamId, string branchId = null)
);
}

[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE, true)]
public bool HasSubscribedBranchUpdated => BranchUpdatedSubscription != null;

#endregion

#region BranchDeleted

[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE, true)]
public delegate void BranchDeletedHandler(object sender, BranchInfo e);

[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE, true)]
public event BranchDeletedHandler OnBranchDeleted;

[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE)]
public IDisposable BranchDeletedSubscription { get; private set; }

/// <summary>
/// Subscribe to events of branch deleted for a stream
/// </summary>
/// <returns></returns>
[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE)]
public void SubscribeBranchDeleted(string streamId)
{
var request = new GraphQLRequest { Query = $@"subscription {{ branchDeleted (streamId: ""{streamId}"") }}" };
Expand All @@ -81,6 +96,7 @@ public void SubscribeBranchDeleted(string streamId)
);
}

[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE, true)]
public bool HasSubscribedBranchDeleted => BranchDeletedSubscription != null;

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ namespace Speckle.Core.Api;
public partial class Client
{
#region CommitCreated

[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE, true)]
public delegate void CommitCreatedHandler(object sender, CommitInfo e);

[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE, true)]
public event CommitCreatedHandler OnCommitCreated;

[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE)]
public IDisposable CommitCreatedSubscription;

/// <summary>
/// Subscribe to events of commit created for a stream
/// </summary>
/// <returns></returns>
[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE, true)]
public void SubscribeCommitCreated(string streamId)
{
var request = new GraphQLRequest { Query = $@"subscription {{ commitCreated (streamId: ""{streamId}"") }}" };
Expand All @@ -28,21 +32,26 @@ public void SubscribeCommitCreated(string streamId)
);
}

[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE, true)]
public bool HasSubscribedCommitCreated => CommitCreatedSubscription != null;

#endregion

#region CommitUpdated

[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE, true)]
public delegate void CommitUpdatedHandler(object sender, CommitInfo e);

[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE, true)]
public event CommitUpdatedHandler OnCommitUpdated;

[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE)]
public IDisposable CommitUpdatedSubscription;

/// <summary>
/// Subscribe to events of commit updated for a stream
/// </summary>
/// <returns></returns>
[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE)]
public void SubscribeCommitUpdated(string streamId, string commitId = null)
{
var request = new GraphQLRequest
Expand All @@ -57,21 +66,27 @@ public void SubscribeCommitUpdated(string streamId, string commitId = null)
);
}

[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE, true)]
public bool HasSubscribedCommitUpdated => CommitUpdatedSubscription != null;

#endregion

#region CommitDeleted

[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE, true)]
public delegate void CommitDeletedHandler(object sender, CommitInfo e);

[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE, true)]
public event CommitDeletedHandler OnCommitDeleted;

[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE)]
public IDisposable CommitDeletedSubscription;

/// <summary>
/// Subscribe to events of commit updated for a stream
/// </summary>

/// <returns></returns>
[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE, true)]
public void SubscribeCommitDeleted(string streamId)
{
var request = new GraphQLRequest { Query = $@"subscription {{ commitDeleted (streamId: ""{streamId}"") }}" };
Expand All @@ -81,6 +96,7 @@ public void SubscribeCommitDeleted(string streamId)
);
}

[Obsolete(DeprecationMessages.FE1_DEPRECATION_MESSAGE, true)]
public bool HasSubscribedCommitDeleted => CommitDeletedSubscription != null;

#endregion
Expand Down
Loading

0 comments on commit 2861ade

Please sign in to comment.