store has a first copy of readme from cache is no waiting
This commit is contained in:
@@ -37,6 +37,22 @@ export const getFiles = async (
|
||||
return treeResponse?.data.tree.filter((t) => t.type === 'blob') ?? []
|
||||
}
|
||||
|
||||
export const getCachedMainReadme = async (owner: string, repo: string) => {
|
||||
if (!owner || !repo) {
|
||||
return null
|
||||
}
|
||||
const { render } = useMarkdown()
|
||||
|
||||
const { getCachedNote } = useNoteCache(`${owner}-${repo}-README`)
|
||||
const cachedReadme = await getCachedNote()
|
||||
|
||||
if (!cachedReadme) {
|
||||
return null
|
||||
}
|
||||
|
||||
return render(cachedReadme.content)
|
||||
}
|
||||
|
||||
export const getMainReadme = async (owner: string, repo: string) => {
|
||||
if (!owner || !repo) {
|
||||
return null
|
||||
@@ -47,8 +63,6 @@ export const getMainReadme = async (owner: string, repo: string) => {
|
||||
`${owner}-${repo}-README`
|
||||
)
|
||||
|
||||
const cachedReadme = await getCachedNote()
|
||||
|
||||
try {
|
||||
const octokit = await getOctokit()
|
||||
|
||||
@@ -63,6 +77,8 @@ export const getMainReadme = async (owner: string, repo: string) => {
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(error)
|
||||
const cachedReadme = await getCachedNote()
|
||||
|
||||
if (cachedReadme) {
|
||||
return render(cachedReadme.content)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { RepoFile } from '@/modules/repo/interfaces/RepoFile'
|
||||
import { UserSettings } from '@/modules/repo/interfaces/UserSettings'
|
||||
import {
|
||||
getCachedMainReadme,
|
||||
getFiles,
|
||||
getMainReadme,
|
||||
getUserSettingsContent
|
||||
@@ -36,14 +37,20 @@ export const useUserRepoStore = defineStore({
|
||||
} catch (error) {
|
||||
console.warn('impossible to refresh token')
|
||||
}
|
||||
const [cachedReadme] = await Promise.all([
|
||||
getCachedMainReadme(newUser, newRepo)
|
||||
])
|
||||
|
||||
this.readme = cachedReadme
|
||||
|
||||
const [readme, files] = await Promise.all([
|
||||
getMainReadme(newUser, newRepo),
|
||||
getFiles(newUser, newRepo)
|
||||
])
|
||||
this.userSettings = await getUserSettingsContent(newUser, newRepo, files)
|
||||
|
||||
this.readme = readme
|
||||
this.files = files
|
||||
|
||||
this.userSettings = await getUserSettingsContent(newUser, newRepo, files)
|
||||
},
|
||||
resetUserRepo() {
|
||||
this.user = ''
|
||||
|
||||
Reference in New Issue
Block a user