mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 23:16:49 +00:00
perf(PostBlocks 转换使用缓存优化): 复杂的数据转换函数使用缓存优化
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user