Skip to content

Commit

Permalink
fix(datastore): Remove unnecessary synchronized causing subscription …
Browse files Browse the repository at this point in the history
…slowness (#2718)
  • Loading branch information
tylerjroach authored Feb 16, 2024
1 parent c839191 commit 1804551
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public final class SubscriptionEndpointTest {
private SubscriptionEndpoint subscriptionEndpoint;
private String eventId;
private Set<String> subscriptionIdsForRelease;
private ApiConfiguration apiConfiguration;

/**
* Create an {@link SubscriptionEndpoint}.
Expand All @@ -68,7 +69,7 @@ public void setup() throws ApiException, JSONException {
.getJSONObject("plugins")
.getJSONObject("awsAPIPlugin");
AWSApiPluginConfiguration pluginConfiguration = AWSApiPluginConfigurationReader.readFrom(configJson);
ApiConfiguration apiConfiguration = pluginConfiguration.getApi(endpointConfigKey);
apiConfiguration = pluginConfiguration.getApi(endpointConfigKey);
assertNotNull(apiConfiguration);

final GraphQLResponse.Factory responseFactory = new GsonGraphQLResponseFactory();
Expand Down Expand Up @@ -184,6 +185,7 @@ private String subscribeToEventComments(String eventId) throws ApiException {
executor.execute(() ->
subscriptionEndpoint.requestSubscription(
request,
apiConfiguration.getAuthorizationType(),
onResult,
item -> {
final String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,7 @@ final class SubscriptionEndpoint {
this.okHttpClient = okHttpClientBuilder.build();
}

synchronized <T> void requestSubscription(
@NonNull GraphQLRequest<T> request,
@NonNull Consumer<String> onSubscriptionStarted,
@NonNull Consumer<GraphQLResponse<T>> onNextItem,
@NonNull Consumer<ApiException> onSubscriptionError,
@NonNull Action onSubscriptionComplete) {
requestSubscription(request,
apiConfiguration.getAuthorizationType(),
onSubscriptionStarted,
onNextItem,
onSubscriptionError,
onSubscriptionComplete);
}

synchronized <T> void requestSubscription(
<T> void requestSubscription(
@NonNull GraphQLRequest<T> request,
@NonNull AuthorizationType authType,
@NonNull Consumer<String> onSubscriptionStarted,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ synchronized void startSubscriptions() throws DataStoreException {
LOG.debug("Waiting for subscriptions to start.");
subscriptionsStarted = latch.abortableAwait(adjustedTimeoutSeconds, TimeUnit.SECONDS);
} catch (InterruptedException exception) {
LOG.warn("Subscription operations were interrupted during setup.");
return;
String errorMessage = "Subscription operations were interrupted during setup.";
LOG.warn(errorMessage);
throw new DataStoreException(errorMessage, "Retry");
}

if (subscriptionsStarted) {
Expand Down

0 comments on commit 1804551

Please sign in to comment.