perf(PostBlocks 转换使用缓存优化): 复杂的数据转换函数使用缓存优化

This commit is contained in:
anime
2025-01-02 18:36:14 +08:00
parent 3e1e4b0c17
commit 2766cb8d3b

View File

@@ -1,6 +1,9 @@
import BLOG from '@/blog.config'
import { getDataFromCache, setDataToCache } from '@/lib/cache/cache_manager'
import { NotionAPI } from 'notion-client'
import {
getDataFromCache,
getOrSetDataWithCache,
setDataToCache
} from '@/lib/cache/cache_manager'
import { deepClone, delay } from '../utils'
import getNotionAPI from '@/lib/notion/getNotionAPI'
@@ -16,7 +19,13 @@ export async function getPage(id, from = null, slice) {
let pageBlock = await getDataFromCache(cacheKey)
if (pageBlock) {
// console.debug('[API<<--缓存]', `from:${from}`, cacheKey)
return convertNotionBlocksToPost(id, pageBlock, slice)
return await getOrSetDataWithCache(
`page_converted_block_${id}_${slice}`,
convertNotionBlocksToPost,
id,
pageBlock,
slice
)
}
// 抓取最新数据
@@ -24,7 +33,13 @@ export async function getPage(id, from = null, slice) {
if (pageBlock) {
await setDataToCache(cacheKey, pageBlock)
return convertNotionBlocksToPost(id, pageBlock, slice)
return await getOrSetDataWithCache(
`page_converted_block_${id}_${slice}`,
convertNotionBlocksToPost,
id,
pageBlock,
slice
)
}
return pageBlock
}