Skip to content

Commit

Permalink
Cache divisions data for 1 hour
Browse files Browse the repository at this point in the history
  • Loading branch information
Allypost committed Aug 13, 2023
1 parent 273dd96 commit 7f98ace
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
11 changes: 8 additions & 3 deletions src/pages/divisions/[slug]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@ export const getServerSideProps = async (
type Props = ServerSideProps<typeof getServerSideProps>;

const PageDivisionSpecificHome: NextPage<Props> = (props) => {
const [division] = api.divisions.getDivision.useSuspenseQuery({
slug: props.slug ?? "",
});
const [division] = api.divisions.getDivision.useSuspenseQuery(
{
slug: props.slug ?? "",
},
{
cacheTime: 60 * 60 * 1000,
},
);

if (!props.slug || !division) {
return null;
Expand Down
26 changes: 5 additions & 21 deletions src/pages/divisions/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type GetServerSidePropsContext, type NextPage } from "next";
import { type NextPage } from "next";
import Link from "next/link";
import { NextSeo } from "next-seo";
import {
Expand All @@ -10,10 +10,8 @@ import {
import { RxArrowRight as IconArrowRight } from "react-icons/rx";

import AppImage from "~/components/base/image/app-image";
import { type ServerSideProps } from "~/types/server";
import { cn } from "~/utils/class";
import { api } from "~/utils/queryApi";
import { createApi } from "~/utils/serverApi";

const SidebarCard: FC<
PropsWithChildren<
Expand All @@ -34,24 +32,10 @@ const SidebarCard: FC<
);
};

export const getServerSideProps = async (
context: GetServerSidePropsContext,
) => {
const helpers = await createApi(context);

await helpers.divisions.getDivisions.prefetch();

return {
props: {
trpcState: helpers.dehydrate(),
},
};
};

type Props = ServerSideProps<typeof getServerSideProps>;

const PageDivisionsHome: NextPage<Props> = () => {
const [divisions] = api.divisions.getDivisions.useSuspenseQuery();
const PageDivisionsHome: NextPage = () => {
const [divisions] = api.divisions.getDivisions.useSuspenseQuery(undefined, {
cacheTime: 60 * 60 * 1000,
});

return (
<>
Expand Down

0 comments on commit 7f98ace

Please sign in to comment.