Skip to content

Commit

Permalink
blog post cache timing
Browse files Browse the repository at this point in the history
  • Loading branch information
nichtsam committed Dec 2, 2024
1 parent 47bc4e4 commit adf45c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/routes/_site+/blog_.$slug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const loader = async ({ params }: LoaderFunctionArgs) => {
timing.timeEnd('get post mdx bundle')

timing.time('bundle post mdx', 'Bundle post mdx')
const { code } = await bundleMDX({ slug, bundle: mdxBundle })
const { code } = await bundleMDX({ slug, bundle: mdxBundle, timing })
timing.timeEnd('bundle post mdx')

timing.time('get post meta', 'Get post meta')
Expand Down
10 changes: 7 additions & 3 deletions app/utils/mdx/compile-mdx.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { remember } from '@epic-web/remember'
import { bundleMDX as _bundleMDX } from 'mdx-bundler'
import PQueue from 'p-queue'
import { cachified, longLivedCache } from '../cache.server.ts'
import { type ServerTiming } from '../timings.server.ts'
import { type MdxBundleSource } from './mdx.server.ts'

async function bundleMDX({ source, files }: MdxBundleSource) {
Expand Down Expand Up @@ -33,17 +34,20 @@ const queue = remember(
const queuedBundleMDX = async (...args: Parameters<typeof bundleMDX>) =>
await queue.add(() => bundleMDX(...args), { throwOnTimeout: true })

const cachedBundleMDX = ({
function cachedBundleMDX({
slug,
bundle,
timing,
}: {
slug: string
bundle: MdxBundleSource
}) => {
const key = `${slug}:compiled`
timing?: ServerTiming
}) {
const key = `mdx:${slug}:compile`
const compileMdx = cachified({
key,
cache: longLivedCache,
timing,
getFreshValue: () => queuedBundleMDX(bundle),
})

Expand Down

0 comments on commit adf45c4

Please sign in to comment.