Stop caching GitHub status requests
This commit is contained in:
parent
f246460130
commit
74baa3d8f4
@ -10,7 +10,7 @@ export default function GitHubForkStatusBadgeClient({
|
||||
tooltip,
|
||||
}: {
|
||||
label?: ReactNode
|
||||
style?: 'success' | 'warning' | 'mono'
|
||||
style?: 'success' | 'warning' | 'error' | 'mono'
|
||||
tooltip?: ReactNode
|
||||
}) {
|
||||
const classNameForStyle = () => {
|
||||
@ -22,11 +22,17 @@ export default function GitHubForkStatusBadgeClient({
|
||||
'border-green-300/40 dark:border-green-900/50',
|
||||
);
|
||||
case 'warning': return clsx(
|
||||
'text-amber-800/90 hover:text-amber-700',
|
||||
'text-amber-800/90 hover:text-amber-800/90',
|
||||
'dark:text-amber-400 dark:hover:text-amber-400',
|
||||
'bg-amber-100/40 dark:bg-amber-900/25',
|
||||
'border-amber-300/40 dark:border-amber-900/50',
|
||||
);
|
||||
case 'error': return clsx(
|
||||
'text-red-700/90 hover:text-red-700/90',
|
||||
'dark:text-red-400 dark:hover:text-red-400',
|
||||
'bg-red-100/20 dark:bg-red-900/25',
|
||||
'border-red-300/40 dark:border-red-900/50',
|
||||
);
|
||||
default: return clsx(
|
||||
'text-main',
|
||||
'bg-white dark:bg-transparent',
|
||||
|
||||
@ -20,28 +20,43 @@ export default async function GitHubForkStatusBadgeServer() {
|
||||
isBehind,
|
||||
label,
|
||||
description,
|
||||
didError,
|
||||
} = await getGitHubMetaWithFallback({ owner, repo, branch, commit });
|
||||
|
||||
const repoLink = (text: string) =>
|
||||
<a
|
||||
href={getGitHubRepoUrl({ owner, repo })}
|
||||
target="_blank"
|
||||
className="underline hover:no-underline hover:text-main"
|
||||
>
|
||||
{text}
|
||||
</a>;
|
||||
|
||||
const isBehindContent = <>
|
||||
{' '}
|
||||
{repoLink('Sync on GitHub')} for latest updates.
|
||||
</>;
|
||||
|
||||
const didErrorContent = <>
|
||||
{' '}
|
||||
Could not connect to {repoLink('GitHub')}.
|
||||
</>;
|
||||
|
||||
return isForkedFromBase || isBaseRepo
|
||||
? <GitHubForkStatusBadgeClient {...{
|
||||
url,
|
||||
label,
|
||||
tooltip: <>
|
||||
{description}
|
||||
{isBehind && <>
|
||||
{' '}
|
||||
<a
|
||||
href={getGitHubRepoUrl({ owner, repo })}
|
||||
target="_blank"
|
||||
className="underline hover:no-underline hover:text-main"
|
||||
>
|
||||
Sync on GitHub
|
||||
</a>
|
||||
{' '}
|
||||
for latest updates.
|
||||
</>}
|
||||
{didError
|
||||
? didErrorContent
|
||||
: isBehind
|
||||
? isBehindContent
|
||||
: null}
|
||||
</>,
|
||||
style: isBehind === undefined || isBehind ? 'warning' : 'mono',
|
||||
style: didError || isBehind === undefined || isBehind
|
||||
? 'warning'
|
||||
: 'mono',
|
||||
}} />
|
||||
: null;
|
||||
}
|
||||
|
||||
@ -5,14 +5,13 @@ import {
|
||||
} from '@/site/config';
|
||||
|
||||
const DEFAULT_BRANCH = 'main';
|
||||
|
||||
const FALLBACK_TEXT = 'Unknown';
|
||||
const CACHE_GITHUB_REQUESTS = false;
|
||||
|
||||
// Cache all results for 2 minutes to avoid rate limiting
|
||||
// GitHub API requests limited to 60 requests per hour
|
||||
const FETCH_CONFIG: RequestInit = {
|
||||
next: { revalidate: 120 },
|
||||
};
|
||||
const FETCH_CONFIG: RequestInit = CACHE_GITHUB_REQUESTS
|
||||
? { next: { revalidate: 120 } } : {};
|
||||
|
||||
interface RepoParams {
|
||||
owner?: string
|
||||
@ -152,6 +151,7 @@ const getGitHubMeta = async (params: RepoParams) => {
|
||||
isBehind,
|
||||
label,
|
||||
description,
|
||||
didError: false,
|
||||
};
|
||||
};
|
||||
|
||||
@ -166,6 +166,7 @@ export const getGitHubMetaWithFallback = (params: RepoParams) =>
|
||||
behindBy: undefined,
|
||||
isBehind: undefined,
|
||||
label: FALLBACK_TEXT,
|
||||
description: FALLBACK_TEXT,
|
||||
description: 'Could not connect to GitHub.',
|
||||
didError: true,
|
||||
};
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user