Skip to content

Commit

Permalink
refactor(electron): always save one update to electron
Browse files Browse the repository at this point in the history
  • Loading branch information
pengx17 committed May 22, 2024
1 parent f50e240 commit bcce30e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/frontend/electron/src/helper/db/workspace-db-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -87,12 +87,16 @@ export class WorkspaceSQLiteDB {

async addUpdateToSQLite(update: Uint8Array, subdocId: string) {
this.update$.next();
await this.adapter.addUpdateToSQLite([
{
data: update,
docId: this.toDBDocId(subdocId),
},
]);
await this.transaction(async () => {
const dbID = this.toDBDocId(subdocId);
const oldUpdate = await this.adapter.getUpdates(dbID);
await this.adapter.replaceUpdates(dbID, [
{
data: mergeUpdate([...oldUpdate.map(u => u.data), update]),
docId: dbID,
},
]);
});
}

async deleteUpdate(subdocId: string) {
Expand Down

0 comments on commit bcce30e

Please sign in to comment.