Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Cache redundant query in settings and header #105

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
5 changes: 3 additions & 2 deletions src/server/check-user-exists.ts
Original file line number Diff line number Diff line change
@@ -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;
};
});
5 changes: 3 additions & 2 deletions src/server/verify-membership-payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -47,5 +48,5 @@ export const verifyMembershipPayment = async (clerkId: string) => {
} catch {
return { paid: false as const };
}
};
});
export type MembershipPayment = Awaited<ReturnType<typeof verifyMembershipPayment>>;
Loading