chore(server): add auto index batch size (#12391)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Added a configurable batch size setting for automatic workspace indexing. Users can now adjust how many workspaces are indexed per batch, with a default value of 10 and support for values between 1 and 1000.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
fengmk2
2025-05-21 08:35:51 +00:00
parent 5b46c66f52
commit ff15779208
4 changed files with 22 additions and 2 deletions

View File

@@ -834,6 +834,11 @@
"type": "string", "type": "string",
"description": "Indexer search service auth password, if not set, basic auth will be disabled. Optional for elasticsearch\n@default \"\"\n@environment `AFFINE_INDEXER_SEARCH_PASSWORD`", "description": "Indexer search service auth password, if not set, basic auth will be disabled. Optional for elasticsearch\n@default \"\"\n@environment `AFFINE_INDEXER_SEARCH_PASSWORD`",
"default": "" "default": ""
},
"autoIndex.batchSize": {
"type": "number",
"description": "Number of workspaces automatically indexed per batch\n@default 10",
"default": 10
} }
} }
}, },

View File

@@ -19,6 +19,9 @@ declare global {
username: string; username: string;
password: string; password: string;
}; };
autoIndex: {
batchSize: number;
};
}; };
} }
} }
@@ -58,4 +61,9 @@ defineModuleConfig('indexer', {
default: '', default: '',
env: ['AFFINE_INDEXER_SEARCH_PASSWORD', 'string'], env: ['AFFINE_INDEXER_SEARCH_PASSWORD', 'string'],
}, },
'autoIndex.batchSize': {
desc: 'Number of workspaces automatically indexed per batch',
default: 10,
shape: z.number().int().positive().max(1000),
},
}); });

View File

@@ -121,7 +121,7 @@ export class IndexerJob {
indexed: true, indexed: true,
}); });
} }
this.logger.debug( this.logger.log(
`indexed workspace ${workspaceId} with ${missingDocIds.length} missing docs and ${deletedDocIds.length} deleted docs` `indexed workspace ${workspaceId} with ${missingDocIds.length} missing docs and ${deletedDocIds.length} deleted docs`
); );
} }
@@ -138,7 +138,10 @@ export class IndexerJob {
@OnJob('indexer.autoIndexWorkspaces') @OnJob('indexer.autoIndexWorkspaces')
async autoIndexWorkspaces(payload: Jobs['indexer.autoIndexWorkspaces']) { async autoIndexWorkspaces(payload: Jobs['indexer.autoIndexWorkspaces']) {
const startSid = payload.lastIndexedWorkspaceSid ?? 0; const startSid = payload.lastIndexedWorkspaceSid ?? 0;
const workspaces = await this.models.workspace.listAfterSid(startSid, 100); const workspaces = await this.models.workspace.listAfterSid(
startSid,
this.config.indexer.autoIndex.batchSize
);
if (workspaces.length === 0) { if (workspaces.length === 0) {
// Keep the current sid value when repeating // Keep the current sid value when repeating
return JOB_SIGNAL.Repeat; return JOB_SIGNAL.Repeat;

View File

@@ -289,6 +289,10 @@
"type": "String", "type": "String",
"desc": "Indexer search service auth password, if not set, basic auth will be disabled. Optional for elasticsearch", "desc": "Indexer search service auth password, if not set, basic auth will be disabled. Optional for elasticsearch",
"env": "AFFINE_INDEXER_SEARCH_PASSWORD" "env": "AFFINE_INDEXER_SEARCH_PASSWORD"
},
"autoIndex.batchSize": {
"type": "Number",
"desc": "Number of workspaces automatically indexed per batch"
} }
}, },
"oauth": { "oauth": {