add a more resilient cache system with a global cache for each note from path

This commit is contained in:
Julien Calixte
2024-07-16 21:55:54 +02:00
parent 100d593050
commit 8802ffb5b2
3 changed files with 27 additions and 4 deletions

View File

@@ -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 {