mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-19 19:16:29 +08:00
chore(server): support disable indexer plugin (#12408)
close CLOUD-220 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a new service to handle indexing-related events and scheduled tasks, improving the management of document and workspace indexing. - Added support for configuring the indexer feature via the AFFINE_INDEXER_ENABLED environment variable. - **Bug Fixes** - Ensured that indexing and deletion jobs are only enqueued when the indexer feature is enabled. - **Tests** - Added comprehensive tests for the new indexing event service, covering various configuration scenarios. - Removed obsolete test related to auto-indexing scheduling. - **Chores** - Updated configuration descriptions and mappings to improve clarity and environment variable support. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -3,11 +3,25 @@ import { Transactional } from '@nestjs-cls/transactional';
|
||||
import type { Update } from '@prisma/client';
|
||||
import { Prisma } from '@prisma/client';
|
||||
|
||||
import { PaginationInput } from '../base';
|
||||
import { EventBus, PaginationInput } from '../base';
|
||||
import { DocIsNotPublic } from '../base/error';
|
||||
import { BaseModel } from './base';
|
||||
import { Doc, DocRole, PublicDocMode, publicUserSelect } from './common';
|
||||
|
||||
declare global {
|
||||
interface Events {
|
||||
'doc.created': {
|
||||
workspaceId: string;
|
||||
docId: string;
|
||||
editor?: string;
|
||||
};
|
||||
'doc.updated': {
|
||||
workspaceId: string;
|
||||
docId: string;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export type DocMetaUpsertInput = Omit<
|
||||
Prisma.WorkspaceDocUncheckedCreateInput,
|
||||
'workspaceId' | 'docId'
|
||||
@@ -24,6 +38,10 @@ export type DocMetaUpsertInput = Omit<
|
||||
*/
|
||||
@Injectable()
|
||||
export class DocModel extends BaseModel {
|
||||
constructor(private readonly event: EventBus) {
|
||||
super();
|
||||
}
|
||||
|
||||
// #region Update
|
||||
|
||||
private updateToDocRecord(row: Update): Doc {
|
||||
@@ -338,7 +356,7 @@ export class DocModel extends BaseModel {
|
||||
docId: string,
|
||||
data?: DocMetaUpsertInput
|
||||
) {
|
||||
return await this.db.workspaceDoc.upsert({
|
||||
const doc = await this.db.workspaceDoc.upsert({
|
||||
where: {
|
||||
workspaceId_docId: {
|
||||
workspaceId,
|
||||
@@ -354,6 +372,11 @@ export class DocModel extends BaseModel {
|
||||
docId,
|
||||
},
|
||||
});
|
||||
this.event.emit('doc.updated', {
|
||||
workspaceId,
|
||||
docId,
|
||||
});
|
||||
return doc;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user