mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-13 03:40:48 +00:00
Recreate all workspace indexes tool (#6946)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
78c1938e3e
commit
2ae1b6d4e0
@ -1522,8 +1522,23 @@ export function devTool (
|
||||
.action(async (workspace: string) => {
|
||||
const { dbUrl, mongodbUri } = prepareTools()
|
||||
const wsid = getWorkspaceId(workspace)
|
||||
const endpoint = await getTransactorEndpoint(generateToken(systemAccountEmail, wsid), 'external')
|
||||
await recreateElastic(mongodbUri ?? dbUrl, wsid, endpoint)
|
||||
await recreateElastic(mongodbUri ?? dbUrl, wsid)
|
||||
})
|
||||
|
||||
program
|
||||
.command('recreate-all-elastic-indexes')
|
||||
.description('reindex elastic')
|
||||
.action(async () => {
|
||||
const { dbUrl, mongodbUri } = prepareTools()
|
||||
|
||||
await withDatabase(dbUrl, async (db) => {
|
||||
const workspaces = await listWorkspacesRaw(db)
|
||||
workspaces.sort((a, b) => b.lastVisit - a.lastVisit)
|
||||
for (const workspace of workspaces) {
|
||||
const wsid = getWorkspaceId(workspace.workspace)
|
||||
await recreateElastic(mongodbUri ?? dbUrl, wsid)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
program
|
||||
|
@ -98,24 +98,15 @@ export async function updateField (
|
||||
}
|
||||
}
|
||||
|
||||
export async function recreateElastic (
|
||||
mongoUrl: string,
|
||||
workspaceId: WorkspaceId,
|
||||
transactorUrl: string
|
||||
): Promise<void> {
|
||||
export async function recreateElastic (mongoUrl: string, workspaceId: WorkspaceId): Promise<void> {
|
||||
const client = getMongoClient(mongoUrl)
|
||||
const _client = await client.getClient()
|
||||
const connection = (await connect(transactorUrl, workspaceId, undefined, {
|
||||
mode: 'backup'
|
||||
})) as unknown as CoreClient & BackupClient
|
||||
try {
|
||||
const db = getWorkspaceMongoDB(_client, workspaceId)
|
||||
await db
|
||||
.collection(DOMAIN_DOC_INDEX_STATE)
|
||||
.updateMany({ _class: core.class.DocIndexState }, { $set: { stages: {}, needIndex: true } })
|
||||
await connection.sendForceClose()
|
||||
} finally {
|
||||
client.close()
|
||||
await connection.close()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user