fix(server): use job queue instead event on doc indexing changes (#12893)

close CLOUD-231



#### PR Dependency Tree


* **PR #12893** 👈

This tree was auto-generated by
[Charcoal](https://github.com/danerwilliams/charcoal)

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

## Summary by CodeRabbit

- **Refactor**
- Updated background processing for document indexing and deletion to
use a job queue system instead of event-based triggers.
- **Bug Fixes**
- Improved reliability of embedding updates and deletions by ensuring
tasks are properly queued and processed.
- **Tests**
- Adjusted tests to verify that document operations correctly trigger
job queue actions.
  
No changes to user-facing features or interface.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
fengmk2
2025-06-23 14:56:04 +08:00
committed by GitHub
parent 705d2e9bbe
commit 862a50c982
5 changed files with 30 additions and 27 deletions
@@ -2,8 +2,8 @@ import { Injectable, Logger } from '@nestjs/common';
import { camelCase, chunk, mapKeys, snakeCase } from 'lodash-es';
import {
EventBus,
InvalidIndexerInput,
JobQueue,
SearchProviderNotFound,
} from '../../base';
import { readAllBlocksFromDocSnapshot } from '../../core/utils/blocksuite';
@@ -110,7 +110,7 @@ export class IndexerService {
constructor(
private readonly models: Models,
private readonly factory: SearchProviderFactory,
private readonly event: EventBus
private readonly queue: JobQueue
) {}
async createTables() {
@@ -285,11 +285,12 @@ export class IndexerService {
})),
options
);
this.event.emit('doc.indexer.updated', {
await this.queue.add('copilot.embedding.updateDoc', {
workspaceId,
docId,
});
this.logger.debug(
this.logger.log(
`synced doc ${workspaceId}/${docId} with ${result.blocks.length} blocks`
);
}
@@ -319,12 +320,13 @@ export class IndexerService {
},
options
);
this.logger.debug(`deleted doc ${workspaceId}/${docId}`);
await this.deleteBlocksByDocId(workspaceId, docId, options);
this.event.emit('doc.indexer.deleted', {
await this.queue.add('copilot.embedding.deleteDoc', {
workspaceId,
docId,
});
this.logger.log(`deleted doc ${workspaceId}/${docId}`);
}
async deleteBlocksByDocId(