优化重试请求逻辑

This commit is contained in:
tangly1024
2022-04-29 14:50:54 +08:00
parent 869cd0a3c9
commit 245290d46d
4 changed files with 60 additions and 33 deletions

View File

@@ -3,7 +3,7 @@ import { getDataFromCache, setDataToCache } from '@/lib/cache/cache_manager'
import { getPostBlocks } from '@/lib/notion/getPostBlocks'
import { idToUuid } from 'notion-utils'
import { defaultMapImageUrl } from 'react-notion-x'
import { isIterable } from '../utils'
import { deepClone, isIterable } from '../utils'
import getAllPageIds from './getAllPageIds'
import { getAllPosts } from './getAllPosts'
import { getAllTags } from './getAllTags'
@@ -25,7 +25,9 @@ export async function getGlobalNotionData({
from,
pageType = ['Post']
}) {
const notionPageData = await getNotionPageData({ pageId, from })
// 深拷贝数据
const notionPageData = deepClone(await getNotionPageData({ pageId, from }))
const allPosts = await getAllPosts({ notionPageData, from, pageType })
notionPageData.allPosts = allPosts
// 删除前端不需要的数据
@@ -196,8 +198,9 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) {
if (!pageRecordMap) {
return []
}
pageId = idToUuid(pageId)
const block = pageRecordMap.block
const rawMetadata = block[pageId].value
const rawMetadata = block[pageId]?.value
// Check Type Page-Database和Inline-Database
if (
rawMetadata?.type !== 'collection_view_page' &&
@@ -207,7 +210,6 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) {
return null
}
pageId = idToUuid(pageId)
const collection = Object.values(pageRecordMap.collection)[0]?.value
const collectionQuery = pageRecordMap.collection_query
const schema = collection?.schema