From c7094b669d46c63bc13e344205be4ef549f2c1fc Mon Sep 17 00:00:00 2001 From: DIYgod Date: Wed, 12 Jul 2023 21:53:10 +0100 Subject: [PATCH] feat: remove refresh cache delay --- src/components/site/PostToc.tsx | 5 ++++- src/lib/redis.server.ts | 20 +++++++++----------- src/markdown/index.ts | 4 +++- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/components/site/PostToc.tsx b/src/components/site/PostToc.tsx index 5cf398f6..9419c2b9 100644 --- a/src/components/site/PostToc.tsx +++ b/src/components/site/PostToc.tsx @@ -22,7 +22,10 @@ function generateContent(items: TocResult["map"]) { children.forEach((child: any) => { if (child.type === "inlineMath") { - content += katex.renderToString(child.value, { output: "html" }) + content += katex.renderToString(child.value, { + output: "html", + strict: false, + }) } else if (inlineElements.includes(child.type)) { content += toHtml(toHast(child) || []) } else { diff --git a/src/lib/redis.server.ts b/src/lib/redis.server.ts index c1e5e64e..c6c84c05 100644 --- a/src/lib/redis.server.ts +++ b/src/lib/redis.server.ts @@ -1,6 +1,6 @@ import Redis from "ioredis" -import { REDIS_EXPIRE, REDIS_REFRESH, REDIS_URL } from "~/lib/env.server" +import { REDIS_EXPIRE, REDIS_URL } from "~/lib/env.server" if (!REDIS_URL) { console.error("REDIS_URL not set") @@ -50,21 +50,19 @@ export async function cacheGet(options: { const cacheValue = await redis.get(redisKey) if (cacheValue && cacheValue !== "undefined" && cacheValue !== "null") { if (!options.noUpdate) { - setTimeout(() => { - options.getValueFun().then((value) => { - if (value) { - redis.set(redisKey, JSON.stringify(value), "EX", REDIS_EXPIRE) - } - }) - }, Math.random() * REDIS_REFRESH) + options.getValueFun().then((value) => { + if (value) { + redis.set(redisKey, JSON.stringify(value), "EX", REDIS_EXPIRE) + } + }) } return JSON.parse(cacheValue) } else { if (options.allowEmpty) { - options.getValueFun().then(async (value) => { + options.getValueFun().then((value) => { if (value) { if (options.noUpdate) { - await redis.set(redisKey, JSON.stringify(value)) + redis.set(redisKey, JSON.stringify(value)) } else { redis.set(redisKey, JSON.stringify(value), "EX", REDIS_EXPIRE) } @@ -75,7 +73,7 @@ export async function cacheGet(options: { const value = await options.getValueFun() if (value) { if (options.noUpdate) { - await redis.set(redisKey, JSON.stringify(value)) + redis.set(redisKey, JSON.stringify(value)) } else { redis.set(redisKey, JSON.stringify(value), "EX", REDIS_EXPIRE) } diff --git a/src/markdown/index.ts b/src/markdown/index.ts index 21be6806..35f9998d 100644 --- a/src/markdown/index.ts +++ b/src/markdown/index.ts @@ -219,7 +219,9 @@ export const renderPageContent = ( showLineNumbers: true, }) // Move it to the end as it generates a lot of DOM and requires extensive traversal. - .use(rehypeKatex) + .use(rehypeKatex, { + strict: false, + }) if (!html) { pipeline.use(rehypeReact, {