瀏覽代碼

cache github response for 5 min

Ben Phelps 2 年之前
父節點
當前提交
2271cc0044
共有 1 個文件被更改,包括 5 次插入1 次删除
  1. 5 1
      src/components/version.jsx

+ 5 - 1
src/components/version.jsx

@@ -3,6 +3,8 @@ import useSWR from "swr";
 import { compareVersions } from "compare-versions";
 import { compareVersions } from "compare-versions";
 import { MdNewReleases } from "react-icons/md";
 import { MdNewReleases } from "react-icons/md";
 
 
+import cachedFetch from "utils/proxy/cached-fetch";
+
 export default function Version() {
 export default function Version() {
   const { t, i18n } = useTranslation();
   const { t, i18n } = useTranslation();
 
 
@@ -10,7 +12,9 @@ export default function Version() {
   const revision = process.env.NEXT_PUBLIC_REVISION ?? "dev";
   const revision = process.env.NEXT_PUBLIC_REVISION ?? "dev";
   const version = process.env.NEXT_PUBLIC_VERSION ?? "dev";
   const version = process.env.NEXT_PUBLIC_VERSION ?? "dev";
 
 
-  const { data: releaseData } = useSWR("https://api.github.com/repos/benphelps/homepage/releases");
+  const cachedFetcher = (resource) => cachedFetch(resource, 5).then((res) => res.json());
+
+  const { data: releaseData } = useSWR("https://api.github.com/repos/benphelps/homepage/releases", cachedFetcher);
 
 
   // use Intl.DateTimeFormat to format the date
   // use Intl.DateTimeFormat to format the date
   const formatDate = (date) => {
   const formatDate = (date) => {