diff --git a/src/db/index.ts b/src/db/index.ts index 4046303a..4109b2b7 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -8,4 +8,4 @@ const client = createClient({ authToken: env.DATABASE_AUTH_TOKEN, }); -export const db = drizzle(client, { schema }); +export const db = drizzle(client, { schema, logger: process.env.NODE_ENV === 'development' }); diff --git a/src/server/check-user-exists.ts b/src/server/check-user-exists.ts index b636b22e..2ba4ebe8 100644 --- a/src/server/check-user-exists.ts +++ b/src/server/check-user-exists.ts @@ -1,11 +1,12 @@ import { db } from '@/db'; import { memberTable } from '@/db/schema'; import { eq } from 'drizzle-orm'; +import { cache } from 'react'; -export const checkUserExists = async (clerkUserId: string) => { +export const checkUserExists = cache(async (clerkUserId: string) => { const existingUser = await db .select({ count: memberTable.id }) .from(memberTable) .where(eq(memberTable.clerkId, clerkUserId)); return existingUser.length > 0; -}; +}); diff --git a/src/server/verify-membership-payment.ts b/src/server/verify-membership-payment.ts index 013a6b04..947980b8 100644 --- a/src/server/verify-membership-payment.ts +++ b/src/server/verify-membership-payment.ts @@ -3,9 +3,10 @@ import { memberTable } from '@/db/schema'; import { redisClient } from '@/lib/redis'; import { squareClient } from '@/lib/square'; import { eq } from 'drizzle-orm'; +import { cache } from 'react'; import { updateMemberExpiryDate } from './update-member-expiry-date'; -export const verifyMembershipPayment = async (clerkId: string) => { +export const verifyMembershipPayment = cache(async (clerkId: string) => { // Get user's membership expiry date from the database const [member] = await db .select({ @@ -47,5 +48,5 @@ export const verifyMembershipPayment = async (clerkId: string) => { } catch { return { paid: false as const }; } -}; +}); export type MembershipPayment = Awaited>;