perf: get notes only on demand

This commit is contained in:
Julien Calixte
2025-01-12 13:06:40 +01:00
parent 4512530250
commit baf32ce8e5

View File

@@ -1,4 +1,4 @@
import { asyncComputed, useAsyncState } from '@vueuse/core' import { useAsyncState } from '@vueuse/core'
import { computed, ref } from 'vue' import { computed, ref } from 'vue'
import { data } from '@/data/data' import { data } from '@/data/data'
@@ -14,20 +14,6 @@ export const useOfflineNotes = () => {
const noteCompleted = ref(0) const noteCompleted = ref(0)
const cachedNotesFromSha = asyncComputed(
async () =>
data.getAll<DataType.Note, Note>({
prefix: DataType.Note,
keys: store.files.map((file) => file.sha).filter(Boolean) as string[],
includeDocs: false
}),
[]
)
const cachedNotesSet = computed(
() => new Set(cachedNotesFromSha.value.map((note) => note._id))
)
const cacheAllNotes = async () => { const cacheAllNotes = async () => {
const isInitialized = store.user && store.repo && totalOfNotes.value > 0 const isInitialized = store.user && store.repo && totalOfNotes.value > 0
@@ -35,6 +21,14 @@ export const useOfflineNotes = () => {
return return
} }
const cachedNotesFromSha = await data.getAll<DataType.Note, Note>({
prefix: DataType.Note,
keys: store.files.map((file) => file.sha).filter(Boolean) as string[],
includeDocs: false
})
const cachedNotesSet = new Set(cachedNotesFromSha.map((note) => note._id))
noteCompleted.value = 0 noteCompleted.value = 0
for (const file of store.files) { for (const file of store.files) {
@@ -42,7 +36,7 @@ export const useOfflineNotes = () => {
if ( if (
!file.sha || !file.sha ||
cachedNotesSet.value.has(data.generateId(DataType.Note, file.sha)) cachedNotesSet.has(data.generateId(DataType.Note, file.sha))
) { ) {
continue continue
} }