From bf97a07d1f93c8fbd4baa174854587a6f1b98519 Mon Sep 17 00:00:00 2001 From: liuyi Date: Tue, 12 Dec 2023 06:03:34 +0000 Subject: [PATCH] fix(server): use last update creating time as snasphot update timestamp (#5266) --- packages/backend/server/src/modules/doc/manager.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/backend/server/src/modules/doc/manager.ts b/packages/backend/server/src/modules/doc/manager.ts index aaac29f936..e2306d083a 100644 --- a/packages/backend/server/src/modules/doc/manager.ts +++ b/packages/backend/server/src/modules/doc/manager.ts @@ -464,6 +464,9 @@ export class DocManager implements OnModuleInit, OnModuleDestroy { workspaceId: string, guid: string, doc: Doc, + // we always delay the snapshot update to avoid db overload, + // so the value of `updatedAt` will not be accurate to user's real action time + updatedAt: Date, initialSeq?: number ) { return this.lockSnapshotForUpsert(workspaceId, guid, async () => { @@ -502,6 +505,7 @@ export class DocManager implements OnModuleInit, OnModuleDestroy { data: { blob, state, + updatedAt, }, }); @@ -521,6 +525,8 @@ export class DocManager implements OnModuleInit, OnModuleDestroy { blob, state, seq: initialSeq, + createdAt: updatedAt, + updatedAt, }, }); @@ -565,7 +571,13 @@ export class DocManager implements OnModuleInit, OnModuleDestroy { ...updates.map(u => u.blob) ); - const done = await this.upsert(workspaceId, id, doc, last.seq); + const done = await this.upsert( + workspaceId, + id, + doc, + last.createdAt, + last.seq + ); if (done) { if (snapshot) {