-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[connectors] Upsert and backfill Confluence spaces as `data_source_fo…
…lders` (#9402) * add two API calls to sync ConfluenceSpaces with data_source_folders * fix a small oopsies in IDs * add a backfill script * add concurrent to the migration script * move the calls to front -> core to activities
- Loading branch information
1 parent
e0cdf54
commit 143e777
Showing
3 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
connectors/migrations/20241216_backfill_confluence_folders.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
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", {}); | ||
|
||
for (const connector of connectors) { | ||
const confluenceSpaces = await ConfluenceSpace.findAll({ | ||
attributes: ["spaceId", "name"], | ||
where: { connectorId: connector.id }, | ||
}); | ||
const dataSourceConfig = dataSourceConfigFromConnector(connector); | ||
if (execute) { | ||
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}` | ||
); | ||
} else { | ||
logger.info( | ||
`Found ${confluenceSpaces.length} spaces for connector ${connector.id}` | ||
); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters