Bird
0
0

You want to optimize a Remix loader that fetches posts with their authors but only needs the post title and author name. Which Prisma query is best for performance?

hard📝 Application Q15 of 15
Remix - Performance
You want to optimize a Remix loader that fetches posts with their authors but only needs the post title and author name. Which Prisma query is best for performance?
Aawait prisma.post.findMany({ select: { title: true, author: { select: { name: true } } } });
Bawait prisma.post.findMany({ include: { author: true } });
Cawait prisma.post.findMany();
Dawait prisma.post.findMany({ where: { title: { not: null } } });
Step-by-Step Solution
Solution:
  1. Step 1: Understand data needed

    Only post titles and author names are needed, so selecting only those fields reduces data load.
  2. Step 2: Compare query options

    await prisma.post.findMany({ select: { title: true, author: { select: { name: true } } } }); uses 'select' to fetch only required fields, improving performance. await prisma.post.findMany({ include: { author: true } }); fetches full author data, await prisma.post.findMany(); fetches all post fields, and await prisma.post.findMany({ where: { title: { not: null } } }); filters but does not limit fields.
  3. Final Answer:

    await prisma.post.findMany({ select: { title: true, author: { select: { name: true } } } }); -> Option A
  4. Quick Check:

    Select only needed fields for best performance [OK]
Quick Trick: Use 'select' to fetch only needed fields [OK]
Common Mistakes:
MISTAKES
  • Using 'include' fetches all author fields unnecessarily
  • Fetching all fields wastes resources
  • Filtering without selecting fields doesn't optimize data size

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Remix Quizzes