mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-05 23:16:52 +00:00
减小NEXT_DATA体积
This commit is contained in:
@@ -10,7 +10,7 @@ import { deepClone, delay } from '../utils'
|
||||
* @param {*} slice
|
||||
* @returns
|
||||
*/
|
||||
export async function getPostBlocks(id, from, slice) {
|
||||
export async function getPage(id, from, slice) {
|
||||
const cacheKey = 'page_block_' + id
|
||||
let pageBlock = await getDataFromCache(cacheKey)
|
||||
if (pageBlock) {
|
||||
@@ -27,28 +27,6 @@ export async function getPostBlocks(id, from, slice) {
|
||||
return pageBlock
|
||||
}
|
||||
|
||||
/**
|
||||
* 针对在getDataBaseInfoByNotionAPI=>getPostBlocks中获取不到的溢出的block-id,用此方法另外抓取
|
||||
* @param {*} id
|
||||
* @param {*} from
|
||||
* @returns
|
||||
*/
|
||||
export async function getSingleBlock(id, from) {
|
||||
const cacheKey = 'single_block_' + id
|
||||
let pageBlock = await getDataFromCache(cacheKey)
|
||||
if (pageBlock) {
|
||||
// console.log('[API<<--缓存]', `from:${from}`, cacheKey)
|
||||
return pageBlock
|
||||
}
|
||||
|
||||
pageBlock = await getPageWithRetry(id, 'single_' + from)
|
||||
|
||||
if (pageBlock) {
|
||||
await setDataToCache(cacheKey, pageBlock)
|
||||
}
|
||||
return pageBlock
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用接口,失败会重试
|
||||
* @param {*} id
|
||||
@@ -162,6 +140,11 @@ function filterPostBlocks(id, blockMap, slice) {
|
||||
* @returns
|
||||
*/
|
||||
export const fetchInBatches = async (ids, batchSize = 100) => {
|
||||
// 如果 ids 不是数组,则将其转换为数组
|
||||
if (!Array.isArray(ids)) {
|
||||
ids = [ids]
|
||||
}
|
||||
|
||||
const authToken = BLOG.NOTION_ACCESS_TOKEN || null
|
||||
const api = new NotionAPI({
|
||||
authToken,
|
||||
@@ -171,7 +154,7 @@ export const fetchInBatches = async (ids, batchSize = 100) => {
|
||||
let fetchedBlocks = {}
|
||||
for (let i = 0; i < ids.length; i += batchSize) {
|
||||
const batch = ids.slice(i, i + batchSize)
|
||||
console.log('[API-->>请求] Fetching missing blocks', ids.length)
|
||||
console.log('[API-->>请求] Fetching missing blocks', batch, ids.length)
|
||||
const start = new Date().getTime()
|
||||
const pageChunk = await api.getBlocks(batch)
|
||||
const end = new Date().getTime()
|
||||
|
||||
Reference in New Issue
Block a user