mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-17 01:56:27 +08:00
fix: history may duplicate on concurrency (#14487)
#### PR Dependency Tree * **PR #14487** 👈 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 * **Bug Fixes** * Enhanced history record creation to prevent duplicate entries in concurrent scenarios. * **Tests** * Added validation for idempotent history record creation. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -276,22 +276,16 @@ export class PgWorkspaceDocStorageAdapter extends DocStorageAdapter {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
await this.models.history.create(
|
||||
{
|
||||
spaceId: snapshot.spaceId,
|
||||
docId: snapshot.docId,
|
||||
timestamp: snapshot.timestamp,
|
||||
blob: Buffer.from(snapshot.bin),
|
||||
editorId: snapshot.editor,
|
||||
},
|
||||
historyMaxAge
|
||||
);
|
||||
} catch (e) {
|
||||
// safe to ignore
|
||||
// only happens when duplicated history record created in multi processes
|
||||
this.logger.error('Failed to create history record', e);
|
||||
}
|
||||
await this.models.history.create(
|
||||
{
|
||||
spaceId: snapshot.spaceId,
|
||||
docId: snapshot.docId,
|
||||
timestamp: snapshot.timestamp,
|
||||
blob: Buffer.from(snapshot.bin),
|
||||
editorId: snapshot.editor,
|
||||
},
|
||||
historyMaxAge
|
||||
);
|
||||
|
||||
metrics.doc
|
||||
.counter('history_created_counter', {
|
||||
|
||||
Reference in New Issue
Block a user