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

[connectors] Upsert and backfill Confluence spaces as data_source_folders #9402

Merged
merged 5 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
43 changes: 43 additions & 0 deletions connectors/migrations/20241216_backfill_confluence_folders.ts
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}`
);
}
}
});
15 changes: 15 additions & 0 deletions connectors/src/connectors/confluence/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ import {
BaseConnectorManager,
ConnectorManagerError,
} from "@connectors/connectors/interface";
import { dataSourceConfigFromConnector } from "@connectors/lib/api/data_source_config";
import { concurrentExecutor } from "@connectors/lib/async_utils";
import {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking: it seems there are multiple levels in confluence hierarchy
cf picture: test > test 123 > some files
Are those subspaces ? are those properly taken into account?
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are pages, which are not folders but can be parents to other pages

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this break anything regarding kwsearch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as per IRL: we're good 👍

deleteFolderNode,
upsertFolderNode,
} from "@connectors/lib/data_sources";
import {
ConfluenceConfiguration,
ConfluencePage,
Expand Down Expand Up @@ -322,6 +327,7 @@ export class ConfluenceConnectorManager extends BaseConnectorManager<null> {
new Error(`Connector not found with id ${this.connectorId}`)
);
}
const dataSourceConfig = dataSourceConfigFromConnector(connector);

let spaces: ConfluenceSpaceType[] = [];
// Fetch Confluence spaces only if the intention is to add new spaces to sync.
Expand Down Expand Up @@ -349,6 +355,8 @@ export class ConfluenceConnectorManager extends BaseConnectorManager<null> {
},
});

await deleteFolderNode({ dataSourceConfig, folderId: internalId });

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@philipperolet would you rather delete from core first and then from connectors or the opposite? no strong opinion here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as per IRL: core first 👍

removedSpaceIds.push(confluenceId);
} else if (permission === "read") {
const confluenceSpace = spaces.find((s) => s.id === confluenceId);
Expand All @@ -360,6 +368,13 @@ export class ConfluenceConnectorManager extends BaseConnectorManager<null> {
urlSuffix: confluenceSpace?._links.webui,
});

await upsertFolderNode({
dataSourceConfig,
folderId: internalId,
parents: [internalId],
title: confluenceSpace?.name ?? confluenceId,
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok to make the user wait for this operation to complete?
we could technically do this in the workflow but it leads to higher risks of having the table confluence_spaces and the data_source_folders out of sync IMHO

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd actually rather do it in the activities, that's where we upsert in core

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright, doing that 👍

addedSpaceIds.push(confluenceId);
} else {
return new Err(
Expand Down
Loading