Skip to content

Commit

Permalink
avoid computations on stale reservations on homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
jgravois committed Sep 22, 2024
1 parent 9ee98b9 commit 9ae4c61
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions app/models/reservation.server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type User, Prisma } from "@prisma/client";
import { addDays, addHours, compareAsc, differenceInMinutes, startOfDay, startOfToday } from "date-fns";
import { addDays, addHours, compareAsc, differenceInMinutes, startOfDay, startOfToday, subDays } from "date-fns";

import { prisma } from "~/db.server";

Expand All @@ -24,7 +24,12 @@ export type Reservation = Prisma.ReservationGetPayload<typeof reservationSelect>
// since we allow anonymous requests, we dont return PII
export function getReservations() {
return prisma.reservation.findMany({
select: { ...reservationSelect.select }
select: { ...reservationSelect.select },
where: {
start: {
gt: subDays(startOfToday(), 1)
}
}
});
}

Expand Down
4 changes: 2 additions & 2 deletions app/routes/faq.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import type { MetaFunction } from "@remix-run/node";
import { json, useLoaderData } from "@remix-run/react";

import { Header } from "~/components/Header/Header";
// import { getReservationCount } from "~/models/reservation.server";
import { getReservationCount } from "~/models/reservation.server";

export const meta: MetaFunction = () => [{ title: "Court dibs - faq" }];

export const loader = async () =>
json({ rezCount: "several" /*await getReservationCount()*/ });
json({ rezCount: await getReservationCount() });

export default function FAQ() {
return (
Expand Down

0 comments on commit 9ae4c61

Please sign in to comment.