Back to all reviewers

Minimize database roundtrips

firecrawl/firecrawl
Based on 2 comments
TypeScript

Avoid making multiple database queries when a single query can retrieve the required data. Each database roundtrip adds latency and increases system load. Before making a database call, check if the data is already available or if multiple queries can be combined into one.

Database TypeScript

Reviewer Prompt

Avoid making multiple database queries when a single query can retrieve the required data. Each database roundtrip adds latency and increases system load. Before making a database call, check if the data is already available or if multiple queries can be combined into one.

Common patterns to avoid:

  • Making separate queries for the same entity (e.g., checking permissions then fetching full data)
  • Sequential queries that could be batched
  • Redundant validation queries when data can be validated in the main query

Example of inefficient pattern:

// Inefficient: Two separate queries for the same job
const job = await supabaseGetJobByIdOnlyData(req.params.jobId);
if (!job || job.team_id !== req.auth.team_id) {
  return res.status(403).json({ success: false, error: "Access denied" });
}

const jobData = await supabaseGetJobsById([req.params.jobId]);

Better approach:

// Efficient: Single query with proper error handling
const jobData = await supabaseGetJobsById([req.params.jobId]);
if (!jobData || jobData.length === 0 || jobData[0].team_id !== req.auth.team_id) {
  return res.status(403).json({ success: false, error: "Access denied or not found" });
}

When pagination is necessary due to database limits, ensure it’s truly required and document the reasoning clearly.

2
Comments Analyzed
TypeScript
Primary Language
Database
Category

Source Discussions