Files
remanso/src/hooks/useBacklinks.hook.ts
Julien Calixte b003a3e008 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>
2026-04-04 11:27:45 +02:00

40 lines
883 B
TypeScript

import { useAsyncState } from "@vueuse/core"
import { ComputedRef, onUnmounted, toValue } from "vue"
import { backlinkEventBus } from "@/bus/backlinkEventBus"
import { data, generateId } from "@/data/data"
import { DataType } from "@/data/DataType.enum"
import { BacklinkNote } from "@/modules/note/models/BacklinkNote"
export const useBacklinks = (sha: string | ComputedRef<string>) => {
sha = toValue(sha)
const { state: backlink, execute } = useAsyncState(
data.get<DataType.BacklinkNote, BacklinkNote>(
generateId(DataType.BacklinkNote, sha)
),
null,
{
resetOnExecute: true
}
)
const unsubscribe = backlinkEventBus.addEventBusListener(
({ fileSha }) => {
if (fileSha !== sha) {
return
}
execute()
},
{
retro: true
}
)
onUnmounted(() => unsubscribe())
return {
backlink
}
}