mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-22 20:46:38 +08:00
feat(server): auto fix doc summary (#13448)
close AF-2787 <img width="2424" height="412" alt="image" src="https://github.com/user-attachments/assets/d6dedff5-1904-48b1-8a36-c3189104e45b" /> #### PR Dependency Tree * **PR #13448** 👈 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 * **New Features** * Introduced an automated system that regularly detects and repairs documents with missing summaries in all workspaces. * Added background processing to ensure document summaries are kept up-to-date without manual intervention. * **Tests** * Added new tests to verify detection of documents with empty or non-empty summaries. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { randomUUID } from 'node:crypto';
|
||||
|
||||
import test from 'ava';
|
||||
|
||||
import { createModule } from '../../__tests__/create-module';
|
||||
import { Mockers } from '../../__tests__/mocks';
|
||||
import { Models } from '..';
|
||||
|
||||
const module = await createModule({});
|
||||
|
||||
const models = module.get(Models);
|
||||
const owner = await module.create(Mockers.User);
|
||||
|
||||
test.after.always(async () => {
|
||||
await module.close();
|
||||
});
|
||||
|
||||
test('should find null summary doc ids', async t => {
|
||||
const workspace = await module.create(Mockers.Workspace, {
|
||||
owner,
|
||||
});
|
||||
|
||||
const docId = randomUUID();
|
||||
await module.create(Mockers.DocMeta, {
|
||||
workspaceId: workspace.id,
|
||||
docId,
|
||||
});
|
||||
|
||||
const docIds = await models.doc.findEmptySummaryDocIds(workspace.id);
|
||||
t.deepEqual(docIds, [docId]);
|
||||
});
|
||||
|
||||
test('should ignore summary is not null', async t => {
|
||||
const workspace = await module.create(Mockers.Workspace, {
|
||||
owner,
|
||||
});
|
||||
|
||||
const docId = randomUUID();
|
||||
await module.create(Mockers.DocMeta, {
|
||||
workspaceId: workspace.id,
|
||||
docId,
|
||||
summary: 'test',
|
||||
});
|
||||
|
||||
const docIds = await models.doc.findEmptySummaryDocIds(workspace.id);
|
||||
t.is(docIds.length, 0);
|
||||
});
|
||||
@@ -696,5 +696,18 @@ export class DocModel extends BaseModel {
|
||||
return [count, rows] as const;
|
||||
}
|
||||
|
||||
async findEmptySummaryDocIds(workspaceId: string) {
|
||||
const rows = await this.db.workspaceDoc.findMany({
|
||||
where: {
|
||||
workspaceId,
|
||||
summary: null,
|
||||
},
|
||||
select: {
|
||||
docId: true,
|
||||
},
|
||||
});
|
||||
return rows.map(row => row.docId);
|
||||
}
|
||||
|
||||
// #endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user