Skip to content

Commit 37a3520

Browse files
committed
fix: refresh docs
1 parent 76cc9c2 commit 37a3520

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

apps/web/service/server/cache.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,17 @@ export function writeCacheFile(id: string, content: Object) {
2424
/**
2525
* isFallback: 不启用缓存的情况下,notion 相应失败的兜底处理
2626
* */
27-
export function getCacheContent(id: string, forceEnableCache = false) {
27+
export function getCacheContent(id: string) {
2828
const cacheFileName = path.join(process.cwd(), '.cache', `${id}.json`)
29-
if (process.env.ENABLE_CACHE || forceEnableCache) {
30-
const exists = fs.existsSync(cacheFileName)
31-
console.log(cacheFileName, 'check local cache: ', exists)
32-
if (exists) {
33-
const cacheData = fs.readFileSync(cacheFileName, {
34-
encoding: 'utf-8',
35-
})
36-
if (cacheData) {
37-
console.log('response with cache:', cacheFileName)
38-
return cacheData ? JSON.parse(cacheData) : null
39-
}
29+
const exists = fs.existsSync(cacheFileName)
30+
console.log(cacheFileName, 'check local cache: ', exists)
31+
if (exists) {
32+
const cacheData = fs.readFileSync(cacheFileName, {
33+
encoding: 'utf-8',
34+
})
35+
if (cacheData) {
36+
console.log('response with cache:', cacheFileName)
37+
return cacheData ? JSON.parse(cacheData) : null
4038
}
4139
}
4240
}

apps/web/service/server/doc.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,18 @@ export async function getNotionDocDetail(id: string, notFound: boolean = true):P
1919
}
2020
}
2121
try {
22-
let result = getCacheContent(id);
23-
if(!result){
24-
try{
25-
result = await getNotionDocByIdOrPathFromServer(id);
26-
console.log(id,'get from server ::', result)
27-
}catch (e) {
28-
console.error(id,'fetch doc detail error')
29-
}
30-
}
31-
const forceEnableCache = (!result || !result.recordMap);
32-
if(forceEnableCache){ // 开发环境不适用缓存
33-
result = getCacheContent(id, true);
34-
console.log(id,'fallback get doc from local .cache')
22+
const cacheContent = getCacheContent(id);
23+
let serverContent;
24+
try{
25+
serverContent = await getNotionDocByIdOrPathFromServer(id);
26+
console.log(id,'get from server ::', serverContent)
27+
}catch (e) {
28+
console.error(id,'fetch doc detail error')
3529
}
36-
if (result?.recordMap) {
30+
const responseContent = serverContent || cacheContent;
31+
if (responseContent?.recordMap) {
3732
return {
38-
props: result,
33+
props: responseContent,
3934
revalidate: isDev ? 60 : 5 * 60, // 单位 秒
4035
}
4136
} else {

0 commit comments

Comments
 (0)