mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
搜索、缓存 、页面
This commit is contained in:
@@ -38,7 +38,7 @@ const Modal = dynamic(
|
||||
)
|
||||
const NotionPage = ({ post }) => {
|
||||
if (!post || !post.blockMap) {
|
||||
return <>Loading...</>
|
||||
return <>{post?.summary || ''}</>
|
||||
}
|
||||
|
||||
const zoom = typeof window !== 'undefined' && mediumZoom({
|
||||
|
||||
8
lib/cache/memory_cache.js
vendored
8
lib/cache/memory_cache.js
vendored
@@ -3,14 +3,14 @@ import BLOG from 'blog.config'
|
||||
|
||||
const cacheTime = BLOG.isProd ? 10 * 60 : 120 * 60 // 120 minutes for dev,10 minutes for prod
|
||||
|
||||
export async function getCacheFromMemory (key, options) {
|
||||
return cache.get(key)
|
||||
export async function getCacheFromMemory(key, options) {
|
||||
return await cache.get(key)
|
||||
}
|
||||
|
||||
export async function setCacheToMemory (key, data) {
|
||||
export async function setCacheToMemory(key, data) {
|
||||
await cache.put(key, data, cacheTime * 1000)
|
||||
}
|
||||
|
||||
export async function delCacheFromMemory (key) {
|
||||
export async function delCacheFromMemory(key) {
|
||||
await cache.del(key)
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ export async function getNotionPageData({ pageId, from }) {
|
||||
const cacheKey = 'page_block_' + pageId
|
||||
const data = await getDataFromCache(cacheKey)
|
||||
if (data) {
|
||||
console.log('[请求缓存]:', `from:${from}`, `id:${pageId}`)
|
||||
console.log('[请求缓存]:', `from:${from}`, `root-page-id:${pageId}`)
|
||||
return data
|
||||
}
|
||||
const pageRecordMap = await getPageRecordMapByNotionAPI({ pageId, from })
|
||||
|
||||
@@ -32,8 +32,8 @@
|
||||
"lodash.throttle": "^4.1.1",
|
||||
"memory-cache": "^0.2.0",
|
||||
"next": "^12.0.5",
|
||||
"notion-client": "6.5.0",
|
||||
"notion-utils": "6.5.0",
|
||||
"notion-client": "6.10.0",
|
||||
"notion-utils": "6.10.0",
|
||||
"preact": "^10.5.15",
|
||||
"qrcode.react": "^1.0.1",
|
||||
"react": "17.0.2",
|
||||
|
||||
@@ -93,9 +93,11 @@ const isIterable = obj =>
|
||||
*/
|
||||
async function filterByMemCache(allPosts, keyword) {
|
||||
const filterPosts = []
|
||||
if (keyword) {
|
||||
keyword = keyword.trim()
|
||||
}
|
||||
for (const post of allPosts) {
|
||||
const cacheKey = 'page_block_' + post.id
|
||||
// const page = await getPostBlocks(post.id, 'search')
|
||||
const page = await getDataFromCache(cacheKey)
|
||||
const tagContent = post.tags ? post.tags.join(' ') : ''
|
||||
const categoryContent = post.category ? post.category.join(' ') : ''
|
||||
@@ -110,7 +112,7 @@ async function filterByMemCache(allPosts, keyword) {
|
||||
indexContent = appendText(indexContent, properties, 'caption')
|
||||
})
|
||||
}
|
||||
console.log('搜索是否命中缓存', page !== null, indexContent)
|
||||
console.log('全文搜索缓存', cacheKey, page)
|
||||
post.results = []
|
||||
let hitCount = 0
|
||||
for (const i in indexContent) {
|
||||
@@ -118,7 +120,7 @@ async function filterByMemCache(allPosts, keyword) {
|
||||
if (!c) {
|
||||
continue
|
||||
}
|
||||
const index = c.toLowerCase().indexOf(keyword.toLowerCase()) || -1
|
||||
const index = c.toLowerCase().indexOf(keyword.toLowerCase())
|
||||
if (index > -1) {
|
||||
hit = true
|
||||
hitCount += 1
|
||||
|
||||
Reference in New Issue
Block a user