-
Notifications
You must be signed in to change notification settings - Fork 115
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
Changes from 4 commits
7bb0307
b85a02e
d9ba75f
d44c317
a1bc51c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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}` | ||
); | ||
} | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
deleteFolderNode, | ||
upsertFolderNode, | ||
} from "@connectors/lib/data_sources"; | ||
import { | ||
ConfluenceConfiguration, | ||
ConfluencePage, | ||
|
@@ -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. | ||
|
@@ -349,6 +355,8 @@ export class ConfluenceConnectorManager extends BaseConnectorManager<null> { | |
}, | ||
}); | ||
|
||
await deleteFolderNode({ dataSourceConfig, folderId: internalId }); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
@@ -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, | ||
}); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok to make the user wait for this operation to complete? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. alright, doing that 👍 |
||
addedSpaceIds.push(confluenceId); | ||
} else { | ||
return new Err( | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 👍