Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make listing all connections for workspace faster. #17004

Merged
merged 8 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static io.airbyte.db.instance.configs.jooq.generated.Tables.OPERATION;
import static io.airbyte.db.instance.configs.jooq.generated.Tables.WORKSPACE;
import static org.jooq.impl.DSL.asterisk;
import static org.jooq.impl.DSL.noCondition;

import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.base.Charsets;
Expand Down Expand Up @@ -622,11 +623,13 @@ public List<StandardSync> listStandardSyncsUsingOperation(final UUID operationId
return getStandardSyncsFromResult(result);
}

public List<StandardSync> listWorkspaceStandardSyncs(final UUID workspaceId) throws IOException {
public List<StandardSync> listWorkspaceStandardSyncs(final UUID workspaceId, final boolean includeDeleted) throws IOException {
final Result<Record> result = database.query(ctx -> ctx.select(CONNECTION.asterisk())
.from(CONNECTION)
.join(ACTOR).on(CONNECTION.SOURCE_ID.eq(ACTOR.ID))
.where(ACTOR.WORKSPACE_ID.eq(workspaceId))).fetch();
.where(ACTOR.WORKSPACE_ID.eq(workspaceId)
.and(includeDeleted ? noCondition() : CONNECTION.STATUS.notEqual(StatusType.deprecated))))
.fetch();
return getStandardSyncsFromResult(result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public static void dbDown() {
void testWorkspaceCountConnections() throws IOException {

final UUID workspaceId = MockData.standardWorkspaces().get(0).getWorkspaceId();
assertEquals(4, configRepository.countConnectionsForWorkspace(workspaceId));
assertEquals(3, configRepository.countConnectionsForWorkspace(workspaceId));
assertEquals(2, configRepository.countDestinationsForWorkspace(workspaceId));
assertEquals(2, configRepository.countSourcesForWorkspace(workspaceId));
}
Expand Down Expand Up @@ -199,12 +199,19 @@ void testSimpleInsertActorCatalog() throws IOException, JsonValidationException,
}

@Test
void testListWorkspaceStandardSync() throws IOException {
void testListWorkspaceStandardSyncAll() throws IOException {

final List<StandardSync> syncs = configRepository.listWorkspaceStandardSyncs(MockData.standardWorkspaces().get(0).getWorkspaceId());
final List<StandardSync> syncs = configRepository.listWorkspaceStandardSyncs(MockData.standardWorkspaces().get(0).getWorkspaceId(), true);
assertThat(MockData.standardSyncs().subList(0, 4)).hasSameElementsAs(syncs);
}

@Test
void testListWorkspaceStandardSyncExcludeDeleted() throws IOException {

final List<StandardSync> syncs = configRepository.listWorkspaceStandardSyncs(MockData.standardWorkspaces().get(0).getWorkspaceId(), false);
assertThat(MockData.standardSyncs().subList(0, 3)).hasSameElementsAs(syncs);
}

@Test
void testGetWorkspaceBySlug()
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ public static List<StandardSync> standardSyncs() {
.withNamespaceFormat("")
.withPrefix("")
.withResourceRequirements(resourceRequirements)
.withStatus(Status.INACTIVE)
.withStatus(Status.DEPRECATED)
.withSchedule(schedule);

final StandardSync standardSync5 = new StandardSync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,7 @@ public ConnectionReadList listConnectionsForWorkspace(final WorkspaceIdRequestBo
throws JsonValidationException, IOException, ConfigNotFoundException {
final List<ConnectionRead> connectionReads = Lists.newArrayList();

// listing all of this is also bad
for (final StandardSync standardSync : configRepository.listWorkspaceStandardSyncs(workspaceIdRequestBody.getWorkspaceId())) {
if (standardSync.getStatus() == StandardSync.Status.DEPRECATED && !includeDeleted) {
continue;
}

for (final StandardSync standardSync : configRepository.listWorkspaceStandardSyncs(workspaceIdRequestBody.getWorkspaceId(), includeDeleted)) {
connectionReads.add(ApiPojoConverters.internalToConnectionRead(standardSync));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,9 @@ void testGetConnection() throws JsonValidationException, ConfigNotFoundException

@Test
void testListConnectionsForWorkspace() throws JsonValidationException, ConfigNotFoundException, IOException {
when(configRepository.listWorkspaceStandardSyncs(source.getWorkspaceId()))
when(configRepository.listWorkspaceStandardSyncs(source.getWorkspaceId(), false))
.thenReturn(Lists.newArrayList(standardSync));
when(configRepository.listWorkspaceStandardSyncs(source.getWorkspaceId(), true))
.thenReturn(Lists.newArrayList(standardSync, standardSyncDeleted));
when(configRepository.getStandardSync(standardSync.getConnectionId()))
.thenReturn(standardSync);
Expand Down