perf(electron): add index for updates (#6951)

![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/T2klNLEk0wxLh4NRDzhk/cd2e982a-f78a-4cc3-b090-ee4c0090e19d.png)

Above image shows the performance on querying a 20k rows of updates table, which is super slow at 150+ms. After adding index for doc_id the performance should be greatly improved.

After:
![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/T2klNLEk0wxLh4NRDzhk/45ea4389-1833-4dc5-bd64-84d8c99cd647.png)

fix TOV-866
This commit is contained in:
pengx17
2024-05-16 06:30:53 +00:00
parent 37cb5b86f4
commit 27af9b4d1a
10 changed files with 443 additions and 342 deletions
@@ -37,10 +37,7 @@ class Doc implements DocType {
if (!apis?.db) {
throw new Error('sqlite datasource is not available');
}
const update = await apis.db.getDocAsUpdates(
this.workspaceId,
this.workspaceId === docId ? undefined : docId
);
const update = await apis.db.getDocAsUpdates(this.workspaceId, docId);
if (update) {
if (
@@ -60,19 +57,18 @@ class Doc implements DocType {
if (!apis?.db) {
throw new Error('sqlite datasource is not available');
}
await apis.db.applyDocUpdate(
this.workspaceId,
data,
this.workspaceId === docId ? undefined : docId
);
await apis.db.applyDocUpdate(this.workspaceId, data, docId);
}
clear(): void | Promise<void> {
return;
}
del(): void | Promise<void> {
return;
async del(docId: string) {
if (!apis?.db) {
throw new Error('sqlite datasource is not available');
}
await apis.db.deleteDoc(this.workspaceId, docId);
}
}