data-performance-optimization

Optimize data retrieval with projections, cursor-based pagination, and N+1 elimination.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/Swear4/agent_rules --skill data-performance-optimization
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: data-performance-optimization
Source: https://github.com/Swear4/agent_rules/tree/main/agent-universal/skills/data-performance-optimization
Command: npx skills add https://github.com/Swear4/agent_rules --skill data-performance-optimization

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Data-heavy applications often suffer from over-fetching, N+1 query patterns, and inefficient pagination, leading to slow responses and high resource usage.

Core Features & Use Cases

  • Projections: enforce explicit field projections on MongoDB queries to minimize data transferred.
  • Cursor-based pagination: replace skip() with cursor-based pagination, including complex cursors for non-unique sort fields, with index guidance.
  • N+1 elimination: apply aggregation pipelines with $lookup or batched $in queries to minimize round-trips.
  • Frontend data access: standardize data fetching via TanStack Query with explicit staleTime and correct invalidation strategies.
  • Use Case: optimize a dashboard displaying thousands of records from MongoDB with minimal latency and predictable memory usage.

Quick Start

Replace all full-document fetches with explicit projections, switch pagination to cursor-based methods, and consolidate frontend data fetching with TanStack Query.

Frequently Asked Questions about data-performance-optimization

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
What is an N+1 query and how do I eliminate it in MongoDB?

An N+1 query fetches parent documents then issues individual fetches per child, causing excessive round-trips. You can eliminate N+1 queries in MongoDB by applying aggregation pipelines with $lookup or batched $in queries to consolidate data retrieval.

How do I switch from offset-based pagination to cursor-based pagination in MongoDB?

To switch to cursor-based pagination, replace the skip() method with cursor queries that use indexed fields. For non-unique sort fields, implement complex cursors and follow index guidance to ensure predictable memory usage and low latency.

How do I stop over-fetching data in MongoDB queries?

To stop over-fetching data in MongoDB, enforce explicit field projections on your queries. By specifying only the required fields in the projection, you minimize the volume of data transferred across your backend API endpoints.

How do I standardize frontend data fetching with TanStack Query?

Standardize frontend data fetching with TanStack Query by configuring explicit staleTime values and implementing correct query invalidation strategies. This ensures efficient caching and predictable data synchronization across your React components.

Does data performance optimization work for dashboards displaying thousands of records?

Yes, data performance optimization is ideal for dashboards displaying thousands of records. By combining explicit MongoDB projections, cursor-based pagination, and TanStack Query, it delivers minimal latency and predictable memory usage for data-heavy interfaces.