diff --git a/lib/notion/getPostBlocks.js b/lib/notion/getPostBlocks.js index d5896ddc..0ab2270c 100644 --- a/lib/notion/getPostBlocks.js +++ b/lib/notion/getPostBlocks.js @@ -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 }