Allow to reindex region (#8610)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2025-04-17 22:07:21 +07:00 committed by GitHub
parent 2326643ccc
commit 10c30e6cc0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -229,7 +229,7 @@ export function devTool (
const uri = dbOverride ?? getAccountDBUrl()
console.log(`connecting to database '${uri}'...`)
const [accountDb, closeAccountsDb] = await getAccountDB(uri)
const [accountDb, closeAccountsDb] = await getAccountDB(uri, process.env.DB_NS)
try {
await f(accountDb)
} catch (err: any) {
@ -2104,7 +2104,8 @@ export function devTool (
program
.command('fulltext-reindex-all')
.description('reindex workspaces')
.action(async () => {
.option('--region <region>', 'region to reindex')
.action(async (cmd: { region?: string }) => {
const fulltextUrl = process.env.FULLTEXT_URL
if (fulltextUrl === undefined) {
console.error('please provide FULLTEXT_URL')
@ -2112,16 +2113,19 @@ export function devTool (
}
await withAccountDatabase(async (db) => {
const workspaces = await listWorkspacesRaw(db)
const workspaces = (await listWorkspacesRaw(db, cmd.region)).filter(
(it) => isActiveMode(it.mode) && it.version?.patch === getModelVersion().patch
)
workspaces.sort((a, b) => b.lastVisit - a.lastVisit)
console.log('workspacess to process', workspaces.length)
for (const workspace of workspaces) {
const wsid = getWorkspaceId(workspace.workspace)
const token = generateToken(systemAccountEmail, wsid)
console.log('reindex workspace', workspace)
console.log('reindex workspace', workspace.workspaceUrl)
await reindexWorkspace(toolCtx, fulltextUrl, token)
console.log('done', workspace)
}
console.log('end-reindex')
})
})