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 { mergeUpdate } from './merge-update';
const TRIM_SIZE = 500;
const TRIM_SIZE = 1;
export class WorkspaceSQLiteDB {
lock = new AsyncLock();
@ -87,12 +87,16 @@ export class WorkspaceSQLiteDB {
async addUpdateToSQLite(update: Uint8Array, subdocId: string) {
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,
docId: this.toDBDocId(subdocId),
data: mergeUpdate([...oldUpdate.map(u => u.data), update]),
docId: dbID,
},
]);
});
}
async deleteUpdate(subdocId: string) {