mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 20:43:30 +01:00
fix(website): caching and revalidation
This commit is contained in:
@@ -17,43 +17,55 @@ export const fetchVersions = cache(async (packageName: string): Promise<string[]
|
|||||||
return ['main'];
|
return ['main'];
|
||||||
}
|
}
|
||||||
|
|
||||||
const { rows } = await sql.execute('select version from documentation where name = ? order by version desc', [
|
try {
|
||||||
packageName,
|
const { rows } = await sql.execute('select version from documentation where name = ? order by version desc', [
|
||||||
]);
|
packageName,
|
||||||
|
]);
|
||||||
|
|
||||||
// @ts-expect-error: https://github.com/planetscale/database-js/issues/71
|
// @ts-expect-error: https://github.com/planetscale/database-js/issues/71
|
||||||
return rows.map((row) => row.version).slice(0, N_RECENT_VERSIONS);
|
return rows.map((row) => row.version).slice(0, N_RECENT_VERSIONS);
|
||||||
|
} catch {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export const fetchModelJSON = cache(async (packageName: string, version: string) => {
|
export const fetchModelJSON = cache(async (packageName: string, version: string) => {
|
||||||
if (process.env.NEXT_PUBLIC_LOCAL_DEV) {
|
if (process.env.NEXT_PUBLIC_LOCAL_DEV) {
|
||||||
let res;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
res = await readFile(join(process.cwd(), '..', '..', 'packages', packageName, 'docs', 'docs.api.json'), 'utf8');
|
const res = await readFile(
|
||||||
|
join(process.cwd(), '..', '..', 'packages', packageName, 'docs', 'docs.api.json'),
|
||||||
|
'utf8',
|
||||||
|
);
|
||||||
|
|
||||||
return JSON.parse(res);
|
return JSON.parse(res);
|
||||||
} catch {
|
} catch {
|
||||||
console.log(res);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview') {
|
if (process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview') {
|
||||||
|
try {
|
||||||
|
const { rows } = await sql.execute('select data from documentation where name = ? and version = ?', [
|
||||||
|
packageName,
|
||||||
|
'main',
|
||||||
|
]);
|
||||||
|
|
||||||
|
// @ts-expect-error: https://github.com/planetscale/database-js/issues/71
|
||||||
|
return rows[0]?.data ?? null;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
const { rows } = await sql.execute('select data from documentation where name = ? and version = ?', [
|
const { rows } = await sql.execute('select data from documentation where name = ? and version = ?', [
|
||||||
packageName,
|
packageName,
|
||||||
'main',
|
version,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// @ts-expect-error: https://github.com/planetscale/database-js/issues/71
|
// @ts-expect-error: https://github.com/planetscale/database-js/issues/71
|
||||||
return rows[0]?.data ?? null;
|
return rows[0]?.data ?? null;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { rows } = await sql.execute('select data from documentation where name = ? and version = ?', [
|
|
||||||
packageName,
|
|
||||||
version,
|
|
||||||
]);
|
|
||||||
|
|
||||||
// @ts-expect-error: https://github.com/planetscale/database-js/issues/71
|
|
||||||
return rows[0]?.data ?? null;
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ import { OVERLOAD_SEPARATOR } from '~/util/constants';
|
|||||||
import { fetchMember } from '~/util/fetchMember';
|
import { fetchMember } from '~/util/fetchMember';
|
||||||
import { findMember } from '~/util/model';
|
import { findMember } from '~/util/model';
|
||||||
|
|
||||||
|
export const revalidate = 3_600;
|
||||||
|
|
||||||
export interface ItemRouteParams {
|
export interface ItemRouteParams {
|
||||||
item: string;
|
item: string;
|
||||||
package: string;
|
package: string;
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import { addPackageToModel } from '~/util/addPackageToModel';
|
|||||||
import { PACKAGES } from '~/util/constants';
|
import { PACKAGES } from '~/util/constants';
|
||||||
import { Providers } from './providers';
|
import { Providers } from './providers';
|
||||||
|
|
||||||
|
export const revalidate = 3_600;
|
||||||
|
|
||||||
const Header = dynamic(async () => import('~/components/Header'));
|
const Header = dynamic(async () => import('~/components/Header'));
|
||||||
const Footer = dynamic(async () => import('~/components/Footer'));
|
const Footer = dynamic(async () => import('~/components/Footer'));
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import { fetchVersions } from '~/app/docAPI';
|
|||||||
import { buttonVariants } from '~/styles/Button';
|
import { buttonVariants } from '~/styles/Button';
|
||||||
import { PACKAGES } from '~/util/constants';
|
import { PACKAGES } from '~/util/constants';
|
||||||
|
|
||||||
|
export const revalidate = 3_600;
|
||||||
|
|
||||||
export default async function Page({ params }: { params: { package: string } }) {
|
export default async function Page({ params }: { params: { package: string } }) {
|
||||||
if (!PACKAGES.includes(params.package)) {
|
if (!PACKAGES.includes(params.package)) {
|
||||||
notFound();
|
notFound();
|
||||||
|
|||||||
Reference in New Issue
Block a user