retrieve all from indexed db in one call
This commit is contained in:
@@ -121,6 +121,7 @@ class Data {
|
||||
keys: keys.map((key) => this.generateId(prefix, key))
|
||||
})
|
||||
|
||||
if (includeDocs) {
|
||||
return response.rows
|
||||
.map((row) => {
|
||||
if ('error' in row) {
|
||||
@@ -129,7 +130,18 @@ class Data {
|
||||
|
||||
return row.doc
|
||||
})
|
||||
.filter((doc) => !!doc) as T[]
|
||||
.filter(Boolean) as T[]
|
||||
} else {
|
||||
return response.rows
|
||||
.map((row) => {
|
||||
if ('error' in row) {
|
||||
return null
|
||||
}
|
||||
|
||||
return { _id: row.id }
|
||||
})
|
||||
.filter(Boolean) as T[]
|
||||
}
|
||||
}
|
||||
|
||||
const response = await this.locale.allDocs({
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { useAsyncState } from '@vueuse/core'
|
||||
import { asyncComputed, useAsyncState } from '@vueuse/core'
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
import { data } from '@/data/data'
|
||||
import { DataType } from '@/data/DataType.enum'
|
||||
import { prepareNoteCache } from '@/modules/note/cache/prepareNoteCache'
|
||||
import { Note } from '@/modules/note/models/Note'
|
||||
import { queryFileContent } from '@/modules/repo/services/repo'
|
||||
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
|
||||
|
||||
@@ -11,6 +14,20 @@ export const useOfflineNotes = () => {
|
||||
|
||||
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 isInitialized = store.user && store.repo && totalOfNotes.value > 0
|
||||
|
||||
@@ -23,20 +40,14 @@ export const useOfflineNotes = () => {
|
||||
for (const file of store.files) {
|
||||
noteCompleted.value++
|
||||
|
||||
if (!file.sha) {
|
||||
if (
|
||||
!file.sha ||
|
||||
cachedNotesSet.value.has(data.generateId(DataType.Note, file.sha))
|
||||
) {
|
||||
continue
|
||||
}
|
||||
|
||||
const { getCachedNote, saveCacheNote } = prepareNoteCache(
|
||||
file.sha,
|
||||
file.path
|
||||
)
|
||||
|
||||
const { from } = await getCachedNote()
|
||||
|
||||
if (from === 'sha') {
|
||||
continue
|
||||
}
|
||||
const { saveCacheNote } = prepareNoteCache(file.sha, file.path)
|
||||
|
||||
const contentFile = await queryFileContent(
|
||||
store.user,
|
||||
|
||||
Reference in New Issue
Block a user