Skip to content

Commit

Permalink
Optimized RSVP limit check to only be performed when RSVPs are enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
mjanderson1227 committed Dec 4, 2024
1 parent 67f3394 commit 331597a
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions apps/web/src/app/rsvp/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,28 @@ export default async function RsvpPage({
return redirect("/i/approval");
}

const rsvpEnabled = await kv.get("config:registration:allowRSVPs");
const rsvpLimit = parseRedisNumber(
await kv.get("config:registration:maxRSVPs"),
c.rsvpDefaultLimit,
const rsvpEnabled = parseRedisBoolean(
await kv.get("config:registration:allowRSVPs") as string | boolean | null | undefined,
true,
);
const rsvpUserCount = await db
.select({ count: count() })
.from(userCommonData)
.where(eq(userCommonData.isRSVPed, true))
.limit(rsvpLimit)
.then((result) => result[0].count);

// TODO: fix type jank here
const isRsvpPossible =
parseRedisBoolean(
rsvpEnabled as string | boolean | null | undefined,
true,
) === true && rsvpUserCount < rsvpLimit;
let isRsvpPossible = false;

if (rsvpEnabled === true) {
const rsvpLimit = parseRedisNumber(
await kv.get("config:registration:maxRSVPs"),
c.rsvpDefaultLimit,
);

const rsvpUserCount = await db
.select({ count: count() })
.from(userCommonData)
.where(eq(userCommonData.isRSVPed, true))
.limit(rsvpLimit)
.then((result) => result[0].count);

isRsvpPossible = rsvpUserCount < rsvpLimit;
}

if (isRsvpPossible || user.isRSVPed === true) {
return (
Expand Down

0 comments on commit 331597a

Please sign in to comment.