perf: move PouchDB/IndexedDB operations to a Web Worker
All database reads and writes now run off the main thread via a dedicated worker, eliminating IndexedDB overhead from the frame budget. - Create data.worker.ts exposing the Data class via Comlink - Refactor data.ts to export a Comlink-wrapped proxy and a standalone generateId() pure function (workers can't expose sync methods cleanly) - Update all 10 call sites to import generateId directly instead of calling data.generateId() Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,7 @@ import { useAsyncState } from "@vueuse/core"
|
||||
import { ComputedRef, onUnmounted, toValue } from "vue"
|
||||
|
||||
import { backlinkEventBus } from "@/bus/backlinkEventBus"
|
||||
import { data } from "@/data/data"
|
||||
import { data, generateId } from "@/data/data"
|
||||
import { DataType } from "@/data/DataType.enum"
|
||||
import { BacklinkNote } from "@/modules/note/models/BacklinkNote"
|
||||
|
||||
@@ -11,7 +11,7 @@ export const useBacklinks = (sha: string | ComputedRef<string>) => {
|
||||
|
||||
const { state: backlink, execute } = useAsyncState(
|
||||
data.get<DataType.BacklinkNote, BacklinkNote>(
|
||||
data.generateId(DataType.BacklinkNote, sha)
|
||||
generateId(DataType.BacklinkNote, sha)
|
||||
),
|
||||
null,
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { watch } from "vue"
|
||||
|
||||
import { backlinkEventBus } from "@/bus/backlinkEventBus"
|
||||
import { data } from "@/data/data"
|
||||
import { data, generateId } from "@/data/data"
|
||||
import { DataType } from "@/data/DataType.enum"
|
||||
import { useFile } from "@/hooks/useFile.hook"
|
||||
import { Backlink } from "@/modules/note/models/Backlink"
|
||||
@@ -42,7 +42,7 @@ export const useComputeBacklinks = () => {
|
||||
continue
|
||||
}
|
||||
|
||||
const fileBacklinkId = data.generateId(DataType.BacklinkNote, file.sha)
|
||||
const fileBacklinkId = generateId(DataType.BacklinkNote, file.sha)
|
||||
const fileBacklink = await data.get<DataType.BacklinkNote, BacklinkNote>(
|
||||
fileBacklinkId
|
||||
)
|
||||
@@ -102,7 +102,7 @@ export const useComputeBacklinks = () => {
|
||||
}
|
||||
|
||||
for (const [sha, fileBacklinks] of backlinks) {
|
||||
const fileBacklinkId = data.generateId(DataType.BacklinkNote, sha)
|
||||
const fileBacklinkId = generateId(DataType.BacklinkNote, sha)
|
||||
const backlinkNote: BacklinkNote = {
|
||||
_id: fileBacklinkId,
|
||||
$type: DataType.BacklinkNote,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useAsyncState } from "@vueuse/core"
|
||||
import { computed, ref } from "vue"
|
||||
|
||||
import { data } from "@/data/data"
|
||||
import { data, generateId } from "@/data/data"
|
||||
import { DataType } from "@/data/DataType.enum"
|
||||
import { prepareNoteCache } from "@/modules/note/cache/prepareNoteCache"
|
||||
import { Note } from "@/modules/note/models/Note"
|
||||
@@ -36,7 +36,7 @@ export const useOfflineNotes = () => {
|
||||
|
||||
if (
|
||||
!file.sha ||
|
||||
cachedNotesSet.has(data.generateId(DataType.Note, file.sha))
|
||||
cachedNotesSet.has(generateId(DataType.Note, file.sha))
|
||||
) {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user