refactor(electron): always save one update to electron (#7009)

not sure do we still need this one
This commit is contained in:
pengx17 2024-05-22 05:03:49 +00:00
parent f50e240e3d
commit fdc33bd3ec
No known key found for this signature in database
GPG Key ID: 23F23D9E8B3971ED

View File

@ -7,7 +7,7 @@ import { getWorkspaceMeta } from '../workspace/meta';
import { SQLiteAdapter } from './db-adapter'; import { SQLiteAdapter } from './db-adapter';
import { mergeUpdate } from './merge-update'; import { mergeUpdate } from './merge-update';
const TRIM_SIZE = 500; const TRIM_SIZE = 1;
export class WorkspaceSQLiteDB { export class WorkspaceSQLiteDB {
lock = new AsyncLock(); lock = new AsyncLock();
@ -87,12 +87,16 @@ export class WorkspaceSQLiteDB {
async addUpdateToSQLite(update: Uint8Array, subdocId: string) { async addUpdateToSQLite(update: Uint8Array, subdocId: string) {
this.update$.next(); this.update$.next();
await this.adapter.addUpdateToSQLite([ await this.transaction(async () => {
const dbID = this.toDBDocId(subdocId);
const oldUpdate = await this.adapter.getUpdates(dbID);
await this.adapter.replaceUpdates(dbID, [
{ {
data: update, data: mergeUpdate([...oldUpdate.map(u => u.data), update]),
docId: this.toDBDocId(subdocId), docId: dbID,
}, },
]); ]);
});
} }
async deleteUpdate(subdocId: string) { async deleteUpdate(subdocId: string) {