add a more resilient cache system with a global cache for each note from path
This commit is contained in:
@@ -18,7 +18,10 @@ export const useFile = (sha: Ref<string> | string, retrieveContent = true) => {
|
||||
renderFromUTF8,
|
||||
getRawContent: getRawContentFromFile
|
||||
} = useMarkdown(toValue(sha))
|
||||
const { getCachedNote, saveCacheNote } = prepareNoteCache(toValue(sha))
|
||||
const { getCachedNote, saveCacheNote } = prepareNoteCache(
|
||||
toValue(sha),
|
||||
toValue(path)
|
||||
)
|
||||
const fromCache = ref(false)
|
||||
|
||||
const rawContent = ref('')
|
||||
|
||||
24
src/modules/note/cache/prepareNoteCache.ts
vendored
24
src/modules/note/cache/prepareNoteCache.ts
vendored
@@ -3,11 +3,24 @@ import { DataType } from '@/data/DataType.enum'
|
||||
import { Note } from '@/modules/note/models/Note'
|
||||
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
|
||||
|
||||
export const prepareNoteCache = (sha: string) => {
|
||||
export const prepareNoteCache = (sha: string, path?: string) => {
|
||||
const store = useUserRepoStore()
|
||||
|
||||
const noteId = data.generateId(DataType.Note, sha)
|
||||
const getCachedNote = async () => data.get<DataType.Note, Note>(noteId)
|
||||
const notePath = path ? data.generateId(DataType.Note, path) : null
|
||||
const getCachedNote = async () => {
|
||||
const note = await data.get<DataType.Note, Note>(noteId)
|
||||
|
||||
if (note) {
|
||||
return note
|
||||
}
|
||||
|
||||
if (notePath) {
|
||||
return data.get<DataType.Note, Note>(notePath)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
const saveCacheNote = async (
|
||||
content: string,
|
||||
@@ -26,6 +39,13 @@ export const prepareNoteCache = (sha: string) => {
|
||||
})
|
||||
|
||||
await data.update(newNote)
|
||||
|
||||
if (notePath) {
|
||||
await data.update({
|
||||
...newNote,
|
||||
_id: notePath
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -49,7 +49,7 @@ watch(mode, async (newMode) => {
|
||||
}
|
||||
|
||||
newContent.value = initialContent
|
||||
const { saveCacheNote } = prepareNoteCache(newSha)
|
||||
const { saveCacheNote } = prepareNoteCache(newSha, newContentPath)
|
||||
await saveCacheNote(encodeUTF8ToBase64(content), {
|
||||
editedSha: newSha,
|
||||
path: newContentPath
|
||||
|
||||
Reference in New Issue
Block a user