retrieve all from indexed db in one call
This commit is contained in:
@@ -121,15 +121,27 @@ class Data {
|
|||||||
keys: keys.map((key) => this.generateId(prefix, key))
|
keys: keys.map((key) => this.generateId(prefix, key))
|
||||||
})
|
})
|
||||||
|
|
||||||
return response.rows
|
if (includeDocs) {
|
||||||
.map((row) => {
|
return response.rows
|
||||||
if ('error' in row) {
|
.map((row) => {
|
||||||
return null
|
if ('error' in row) {
|
||||||
}
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
return row.doc
|
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({
|
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 { computed, ref } from 'vue'
|
||||||
|
|
||||||
|
import { data } from '@/data/data'
|
||||||
|
import { DataType } from '@/data/DataType.enum'
|
||||||
import { prepareNoteCache } from '@/modules/note/cache/prepareNoteCache'
|
import { prepareNoteCache } from '@/modules/note/cache/prepareNoteCache'
|
||||||
|
import { Note } from '@/modules/note/models/Note'
|
||||||
import { queryFileContent } from '@/modules/repo/services/repo'
|
import { queryFileContent } from '@/modules/repo/services/repo'
|
||||||
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
|
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
|
||||||
|
|
||||||
@@ -11,6 +14,20 @@ 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
|
||||||
|
|
||||||
@@ -23,20 +40,14 @@ export const useOfflineNotes = () => {
|
|||||||
for (const file of store.files) {
|
for (const file of store.files) {
|
||||||
noteCompleted.value++
|
noteCompleted.value++
|
||||||
|
|
||||||
if (!file.sha) {
|
if (
|
||||||
|
!file.sha ||
|
||||||
|
cachedNotesSet.value.has(data.generateId(DataType.Note, file.sha))
|
||||||
|
) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const { getCachedNote, saveCacheNote } = prepareNoteCache(
|
const { saveCacheNote } = prepareNoteCache(file.sha, file.path)
|
||||||
file.sha,
|
|
||||||
file.path
|
|
||||||
)
|
|
||||||
|
|
||||||
const { from } = await getCachedNote()
|
|
||||||
|
|
||||||
if (from === 'sha') {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
const contentFile = await queryFileContent(
|
const contentFile = await queryFileContent(
|
||||||
store.user,
|
store.user,
|
||||||
|
|||||||
Reference in New Issue
Block a user