Skip to content

Commit

Permalink
Optimize listDestinationsForWorkspace route (#18456)
Browse files Browse the repository at this point in the history
Add a function to fetch all destinations in a workspace
  • Loading branch information
malikdiarra authored and nataly committed Nov 3, 2022
1 parent b2bbe11 commit 28c2b78
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,22 @@ public List<DestinationConnection> listDestinationConnection() throws JsonValida
return persistence.listConfigs(ConfigSchema.DESTINATION_CONNECTION, DestinationConnection.class);
}

/**
* Returns all destinations for a workspace. Does not contain secrets.
*
* @param workspaceId - id of the workspace
* @return destinations
* @throws IOException - you never know when you IO
*/
public List<DestinationConnection> listWorkspaceDestinationConnection(UUID workspaceId) throws IOException {
final Result<Record> result = database.query(ctx -> ctx.select(asterisk())
.from(ACTOR)
.where(ACTOR.ACTOR_TYPE.eq(ActorType.destination))
.and(ACTOR.WORKSPACE_ID.eq(workspaceId))
.andNot(ACTOR.TOMBSTONE).fetch());
return result.stream().map(DbConverter::buildDestinationConnection).collect(Collectors.toList());
}

public StandardSync getStandardSync(final UUID connectionId) throws JsonValidationException, IOException, ConfigNotFoundException {
return persistence.getConfig(ConfigSchema.STANDARD_SYNC, connectionId.toString(), StandardSync.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,15 @@ void testListWorkspaceSources() throws IOException {
assertThat(sources).hasSameElementsAs(expectedSources);
}

@Test
void testListWorkspaceDestinations() throws IOException {
UUID workspaceId = MockData.standardWorkspaces().get(0).getWorkspaceId();
final List<DestinationConnection> expectedDestinations = MockData.destinationConnections().stream()
.filter(destination -> destination.getWorkspaceId().equals(workspaceId)).collect(Collectors.toList());
final List<DestinationConnection> destinations = configRepository.listWorkspaceDestinationConnection(workspaceId);
assertThat(destinations).hasSameElementsAs(expectedDestinations);
}

@Test
void testSourceDefinitionGrants() throws IOException {
final UUID workspaceId = MockData.standardWorkspaces().get(0).getWorkspaceId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,7 @@ public DestinationReadList listDestinationsForWorkspace(final WorkspaceIdRequest
throws ConfigNotFoundException, IOException, JsonValidationException {
final List<DestinationRead> reads = Lists.newArrayList();

for (final DestinationConnection dci : configRepository.listDestinationConnection()) {
if (!dci.getWorkspaceId().equals(workspaceIdRequestBody.getWorkspaceId())) {
continue;
}

if (dci.getTombstone()) {
continue;
}

for (final DestinationConnection dci : configRepository.listWorkspaceDestinationConnection(workspaceIdRequestBody.getWorkspaceId())) {
reads.add(buildDestinationRead(dci));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ void testListDestinationForWorkspace() throws JsonValidationException, ConfigNot
final WorkspaceIdRequestBody workspaceIdRequestBody = new WorkspaceIdRequestBody().workspaceId(destinationConnection.getWorkspaceId());

when(configRepository.getDestinationConnection(destinationConnection.getDestinationId())).thenReturn(destinationConnection);
when(configRepository.listDestinationConnection()).thenReturn(Lists.newArrayList(destinationConnection));
when(configRepository.listWorkspaceDestinationConnection(destinationConnection.getWorkspaceId()))
.thenReturn(Lists.newArrayList(destinationConnection));
when(configRepository.getStandardDestinationDefinition(standardDestinationDefinition.getDestinationDefinitionId()))
.thenReturn(standardDestinationDefinition);
when(secretsProcessor.prepareSecretsForOutput(destinationConnection.getConfiguration(),
Expand Down

0 comments on commit 28c2b78

Please sign in to comment.