fix(server): avoid updates persist forever (#5258)
This commit is contained in:
@@ -565,7 +565,9 @@ export class DocManager implements OnModuleInit, OnModuleDestroy {
|
|||||||
...updates.map(u => u.blob)
|
...updates.map(u => u.blob)
|
||||||
);
|
);
|
||||||
|
|
||||||
await this.upsert(workspaceId, id, doc, last.seq);
|
const done = await this.upsert(workspaceId, id, doc, last.seq);
|
||||||
|
|
||||||
|
if (done) {
|
||||||
if (snapshot) {
|
if (snapshot) {
|
||||||
this.event.emit('snapshot.updated', {
|
this.event.emit('snapshot.updated', {
|
||||||
id,
|
id,
|
||||||
@@ -578,14 +580,14 @@ export class DocManager implements OnModuleInit, OnModuleDestroy {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const done = await this.upsert(workspaceId, id, doc, last.seq);
|
|
||||||
|
|
||||||
if (done) {
|
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
`Squashed ${updates.length} updates for ${id} in workspace ${workspaceId}`
|
`Squashed ${updates.length} updates for ${id} in workspace ${workspaceId}`
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
await this.db.update.deleteMany({
|
// always delete updates
|
||||||
|
// the upsert will return false if the state is not newer, so we don't need to worry about it
|
||||||
|
const { count } = await this.db.update.deleteMany({
|
||||||
where: {
|
where: {
|
||||||
id,
|
id,
|
||||||
workspaceId,
|
workspaceId,
|
||||||
@@ -595,8 +597,7 @@ export class DocManager implements OnModuleInit, OnModuleDestroy {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.updateCachedUpdatesCount(workspaceId, id, -updates.length);
|
await this.updateCachedUpdatesCount(workspaceId, id, -count);
|
||||||
}
|
|
||||||
|
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user