mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-16 23:16:48 +00:00
perf(使用缓存优化): 复杂的数据转换函数使用缓存优化
This commit is contained in:
@@ -66,13 +66,14 @@ export async function getGlobalData({
|
||||
*/
|
||||
export async function getSiteDataByPageId({ pageId, from }) {
|
||||
// 获取NOTION原始数据,此接支持mem缓存。
|
||||
const pageRecordMap = await getPage(pageId, from)
|
||||
return await getOrSetDataWithCache(
|
||||
`site_data_${pageId}`,
|
||||
converNotionToSiteDate,
|
||||
async (pageId, from) => {
|
||||
const pageRecordMap = await getPage(pageId, from)
|
||||
return converNotionToSiteDate(pageId, from, deepClone(pageRecordMap))
|
||||
},
|
||||
pageId,
|
||||
from,
|
||||
deepClone(pageRecordMap)
|
||||
from
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import BLOG from '@/blog.config'
|
||||
import {
|
||||
getDataFromCache,
|
||||
getOrSetDataWithCache,
|
||||
setDataToCache
|
||||
} from '@/lib/cache/cache_manager'
|
||||
import { getDataFromCache, getOrSetDataWithCache, setDataToCache } from '@/lib/cache/cache_manager'
|
||||
import { deepClone, delay } from '../utils'
|
||||
import getNotionAPI from '@/lib/notion/getNotionAPI'
|
||||
|
||||
@@ -15,33 +11,28 @@ import getNotionAPI from '@/lib/notion/getNotionAPI'
|
||||
* @returns
|
||||
*/
|
||||
export async function getPage(id, from = null, slice) {
|
||||
const cacheKey = `page_block_${id}`
|
||||
let pageBlock = await getDataFromCache(cacheKey)
|
||||
if (pageBlock) {
|
||||
// console.debug('[API<<--缓存]', `from:${from}`, cacheKey)
|
||||
return await getOrSetDataWithCache(
|
||||
`page_converted_block_${id}_${slice}`,
|
||||
convertNotionBlocksToPost,
|
||||
id,
|
||||
pageBlock,
|
||||
slice
|
||||
)
|
||||
}
|
||||
return await getOrSetDataWithCache(
|
||||
`page_content_${id}_${slice}`,
|
||||
async (id, slice) => {
|
||||
const cacheKey = `page_block_${id}`
|
||||
let pageBlock = await getDataFromCache(cacheKey)
|
||||
if (pageBlock) {
|
||||
// console.debug('[API<<--缓存]', `from:${from}`, cacheKey)
|
||||
return convertNotionBlocksToPost(id, pageBlock, slice)
|
||||
}
|
||||
|
||||
// 抓取最新数据
|
||||
pageBlock = await getPageWithRetry(id, from)
|
||||
// 抓取最新数据
|
||||
pageBlock = await getPageWithRetry(id, from)
|
||||
|
||||
if (pageBlock) {
|
||||
await setDataToCache(cacheKey, pageBlock)
|
||||
return await getOrSetDataWithCache(
|
||||
`page_converted_block_${id}_${slice}`,
|
||||
convertNotionBlocksToPost,
|
||||
id,
|
||||
pageBlock,
|
||||
slice
|
||||
)
|
||||
}
|
||||
return pageBlock
|
||||
if (pageBlock) {
|
||||
await setDataToCache(cacheKey, pageBlock)
|
||||
return convertNotionBlocksToPost(id, pageBlock, slice)
|
||||
}
|
||||
return pageBlock
|
||||
},
|
||||
id,
|
||||
slice
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user