mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem Per #52168, dates are a really important signal for LLMs. We should be surfacing this more proactively across our docs, pulling from the lastModified date. ## Solution Looks like this information is already stored in a Supabase table, so we can grab the date values and then render on associated pages. To this end, this PR: - Grabs the last-updated date with a script (with tests on the script). Gets all the dates to form a map, and then have all the pages read from that map to save roundtrips. Still ~20+ lookups b/c of how the site is built (by multiple workers). - Adds that date into the Guides template and associated JSON-LD / opengraph structured data. The goal of these dates -- to answer the various CodeRabbit comments -- are to be an **approximation** of age. It's okay if they're not 100% accurate based on changed titles, frontmatter, deleted heading sections, etc. Reading this via JS instead of a SQL lookup to save us a DB migration, as that's the fastest way to get this change up (and I have very little familiarity with db migrations, so partially just lack of knowledge here). This does add some additional latency to builds, approximately ~20 seconds from some build benchmarking: - https://vercel.com/supabase/docs/7UcfoR3Jjb8SYuUNkRo14W3DZqBL#L1221-L1241 - https://vercel.com/supabase/docs/23RH6uPtR92K8EggPPiTEQvY23bk#L1062-L1085 ## Preview links | state | preview | | -------|------| | after | <img width="891" height="438" alt="image" src="https://github.com/user-attachments/assets/38476245-be80-4b65-99a7-4501e60560fc" /> | - [Queues overview](https://docs-git-kody-devrel-751-docs-last-updated-date-supabase.vercel.app/docs/guides/queues) -- rendered date of Oct 19th matches [git last modified](https://github.com/supabase/supabase/commits/master/apps/docs/content/guides/queues.mdx) - [Cron overview](https://docs-git-kody-devrel-751-docs-last-updated-date-supabase.vercel.app/docs/guides/cron) -- rendered date of Feb 23rd slight diff from git last modified... but matches last [content change](https://github.com/supabase/supabase/commits/master/apps/docs/content/guides/cron.mdx) - [Auth overview](https://docs-git-kody-devrel-751-docs-last-updated-date-supabase.vercel.app/docs/guides/auth) -- rendered date of Oct 22nd matches [git last modified](https://github.com/supabase/supabase/commits/master/apps/docs/content/guides/auth.mdx) ## Gaps / open review questions - **testing** - Least familiar with the tests in `apps/docs/lib/last-changed.test.ts` + these are entirely claude generated. Unsure if they hit what they should. - **build latency** - Is ~20 sec / build acceptable latency here? If we wanted to move forward with SQL instead of JS to try and reduce it, could make sense... but I'd definitely need help on the associated db migration here. - **build fragility** - AI review flagged the cooldown / potential hanging requests without a timeout. Seems like this is now addressed, but obviously could use a sanity check. --------- Co-authored-by: Claude Haiku 5.5 <noreply@anthropic.com> Co-authored-by: anthony lio <lionnet.ant@gmail.com>
120 lines
4.0 KiB
TypeScript
120 lines
4.0 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||
|
||
const { range, abortSignal, captureException } = vi.hoisted(() => {
|
||
const range = vi.fn()
|
||
return {
|
||
range,
|
||
abortSignal: vi.fn((_signal: AbortSignal) => ({ range })),
|
||
captureException: vi.fn(),
|
||
}
|
||
})
|
||
|
||
vi.mock('server-only', () => ({}))
|
||
vi.mock('@sentry/nextjs', () => ({ captureException }))
|
||
vi.mock('~/lib/supabaseAdmin', () => ({
|
||
supabaseAdmin: () => ({
|
||
from: () => ({
|
||
select: () => ({
|
||
like: () => ({
|
||
order: () => ({ abortSignal }),
|
||
}),
|
||
}),
|
||
}),
|
||
}),
|
||
}))
|
||
|
||
const COOLDOWN_MS = 60_000
|
||
|
||
const row = (parent_page: string, last_updated: string) => ({ parent_page, last_updated })
|
||
|
||
async function loadGetGuideLastUpdated() {
|
||
const lastChanged = await import('./last-changed')
|
||
return lastChanged.getGuideLastUpdated
|
||
}
|
||
|
||
describe('getGuideLastUpdated', () => {
|
||
beforeEach(() => {
|
||
vi.resetModules()
|
||
vi.useFakeTimers({ toFake: ['Date'] })
|
||
range.mockReset()
|
||
abortSignal.mockClear()
|
||
captureException.mockReset()
|
||
})
|
||
|
||
afterEach(() => {
|
||
vi.useRealTimers()
|
||
})
|
||
|
||
it('returns the newest last_updated across a page’s section rows', async () => {
|
||
range.mockResolvedValueOnce({
|
||
data: [
|
||
row('/content/guides/auth/jwts.mdx', '2026-10-01T12:00:00+00:00'),
|
||
row('/content/guides/auth/jwts.mdx', '2026-10-05T08:00:00+00:00'),
|
||
row('/content/guides/auth/jwts.mdx', '2026-09-20T08:00:00+00:00'),
|
||
row('/content/guides/auth.mdx', '2026-08-01T00:00:00+00:00'),
|
||
],
|
||
error: null,
|
||
})
|
||
const getGuideLastUpdated = await loadGetGuideLastUpdated()
|
||
|
||
expect(await getGuideLastUpdated(['auth', 'jwts'])).toBe('2026-10-05T08:00:00+00:00')
|
||
expect(await getGuideLastUpdated(['auth'])).toBe('2026-08-01T00:00:00+00:00')
|
||
expect(await getGuideLastUpdated(['auth', 'missing'])).toBeUndefined()
|
||
})
|
||
|
||
it('reads every page of rows under one abort signal', async () => {
|
||
const fullPage = Array.from({ length: 1000 }, (_, i) =>
|
||
row(`/content/guides/auth/page-${i}.mdx`, '2026-10-01T00:00:00+00:00')
|
||
)
|
||
range.mockResolvedValueOnce({ data: fullPage, error: null }).mockResolvedValueOnce({
|
||
data: [row('/content/guides/auth/last.mdx', '2026-10-09T00:00:00+00:00')],
|
||
error: null,
|
||
})
|
||
const getGuideLastUpdated = await loadGetGuideLastUpdated()
|
||
|
||
expect(await getGuideLastUpdated(['auth', 'last'])).toBe('2026-10-09T00:00:00+00:00')
|
||
expect(range).toHaveBeenNthCalledWith(1, 0, 999)
|
||
expect(range).toHaveBeenNthCalledWith(2, 1000, 1999)
|
||
|
||
const [first] = abortSignal.mock.calls[0]
|
||
const [second] = abortSignal.mock.calls[1]
|
||
expect(first).toBeInstanceOf(AbortSignal)
|
||
expect(second).toBe(first)
|
||
})
|
||
|
||
it('reads the table once and reuses the map for later lookups', async () => {
|
||
range.mockResolvedValueOnce({ data: [], error: null })
|
||
const getGuideLastUpdated = await loadGetGuideLastUpdated()
|
||
|
||
await getGuideLastUpdated(['auth'])
|
||
await getGuideLastUpdated(['database', 'tables'])
|
||
|
||
expect(range).toHaveBeenCalledTimes(1)
|
||
})
|
||
|
||
it('returns undefined, reports the error, and skips lookups during the cooldown', async () => {
|
||
range.mockResolvedValueOnce({ data: null, error: new Error('boom') })
|
||
const getGuideLastUpdated = await loadGetGuideLastUpdated()
|
||
|
||
expect(await getGuideLastUpdated(['auth'])).toBeUndefined()
|
||
expect(captureException).toHaveBeenCalledTimes(1)
|
||
|
||
expect(await getGuideLastUpdated(['auth'])).toBeUndefined()
|
||
expect(range).toHaveBeenCalledTimes(1)
|
||
})
|
||
|
||
it('retries once the cooldown after a failed read has passed', async () => {
|
||
range.mockResolvedValueOnce({ data: null, error: new Error('boom') }).mockResolvedValueOnce({
|
||
data: [row('/content/guides/auth.mdx', '2026-10-02T00:00:00+00:00')],
|
||
error: null,
|
||
})
|
||
const getGuideLastUpdated = await loadGetGuideLastUpdated()
|
||
|
||
await getGuideLastUpdated(['auth'])
|
||
vi.setSystemTime(Date.now() + COOLDOWN_MS + 1)
|
||
|
||
expect(await getGuideLastUpdated(['auth'])).toBe('2026-10-02T00:00:00+00:00')
|
||
expect(range).toHaveBeenCalledTimes(2)
|
||
})
|
||
})
|