Skip to content

Commit

Permalink
add concurrent to the migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
aubin-tchoi committed Dec 16, 2024
1 parent d9ba75f commit 6129354
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions connectors/migrations/20241216_backfill_confluence_folders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { makeScript } from "scripts/helpers";

import { makeSpaceInternalId } from "@connectors/connectors/confluence/lib/internal_ids";
import { dataSourceConfigFromConnector } from "@connectors/lib/api/data_source_config";
import { concurrentExecutor } from "@connectors/lib/async_utils";
import { upsertFolderNode } from "@connectors/lib/data_sources";
import { ConfluenceSpace } from "@connectors/lib/models/confluence";
import { ConnectorResource } from "@connectors/resources/connector_resource";

const FOLDER_CONCURRENCY = 10;
makeScript({}, async ({ execute }, logger) => {
const connectors = await ConnectorResource.listByType("confluence", {});

Expand All @@ -16,14 +18,18 @@ makeScript({}, async ({ execute }, logger) => {
});
const dataSourceConfig = dataSourceConfigFromConnector(connector);
if (execute) {
for (const space of confluenceSpaces) {
await upsertFolderNode({
dataSourceConfig,
folderId: makeSpaceInternalId(space.spaceId),
parents: [makeSpaceInternalId(space.spaceId)],
title: space.name,
});
}
await concurrentExecutor(
confluenceSpaces,
async (space) => {
await upsertFolderNode({
dataSourceConfig,
folderId: makeSpaceInternalId(space.spaceId),
parents: [makeSpaceInternalId(space.spaceId)],
title: space.name,
});
},
{ concurrency: FOLDER_CONCURRENCY }
);
logger.info(
`Upserted ${confluenceSpaces.length} spaces for connector ${connector.id}`
);
Expand Down

0 comments on commit 6129354

Please sign in to comment.