N+1 Query Detector for Openclaw

A comprehensive diagnostic tool to find and fix performance-draining N+1 query patterns in ORM-based applications.

charlie-morrison
v1.0.1
May 1, 2026
0
677
0

Install & Download

1. ClawHub CLI

The fastest way to install a skill directly from the registry.

npx clawhub@latest install n-plus-one-detector

2. Manual Installation

Copy the skill folder to one of these locations

Global
~/.openclaw/skills/
Workspace
<project>/skills/

Priority: Workspace > Local > Bundled

3. Prompt Installation

Copy this prompt to OpenClaw to install it automatically.

Help me install n-plus-one-detector using Clawhub. If Clawhub is not installed, install it first (npm i -g clawhub).

Prefer to download?

Get the raw skill files in a ZIP archive.

What is N+1 Query Detector?

The N+1 Query Detector is an essential utility for Openclaw Skills that targets one of the most common performance issues in modern web development. It provides an automated way to scan codebases for inefficient database access patterns where a single request triggers multiple redundant queries. By analyzing how Object-Relational Mappers (ORMs) interact with loops, this skill helps developers implement best practices such as eager loading, joins, and batch fetching to significantly reduce database load and improve response times.

This tool is particularly valuable for complex applications using frameworks like Django, SQLAlchemy, Prisma, or ActiveRecord. It bridges the gap between static code analysis and runtime profiling, offering actionable insights and code-ready fixes to ensure your application remains scalable and efficient within the Openclaw Skills ecosystem.

N+1 Query Detector Use Cases

  • Finding N+1 queries in high-traffic API endpoints to reduce server latency.
  • Auditing legacy codebases to identify missing select_related or prefetch_related calls.
  • Optimizing GraphQL resolvers using the DataLoader pattern to prevent query explosions.
  • Automating performance reviews during the development lifecycle to catch regressions early.

How N+1 Query Detector Works

  1. Technology Identification: Scans the project to determine the specific ORM and programming language in use.
  2. Static Pattern Analysis: Uses advanced search patterns to find loops that contain database query calls across various languages including Python, JS/TS, Ruby, and Go.
  3. Runtime Analysis: Provides scripts to log and normalize SQL queries in development environments to count exact query execution per request.
  4. Issue Classification: Categorizes detected problems into patterns like lazy-loading, async queries in loops, or resolver-based N+1 issues.
  5. Automated Reporting: Generates a detailed Markdown report with specific code recommendations and estimated performance impact.

N+1 Query Detector Setup

To begin using the N+1 Query Detector within Openclaw Skills, ensure your environment is prepared for static analysis by installing ripgrep.

# Install ripgrep (rg) if not already available for static scanning
sudo apt-get install ripgrep

# Execute the detection logic on your source directory
rg "from sqlalchemy|from django\\.db|ActiveRecord|prisma" --stats

No complex configuration is required as the skill automatically detects most popular ORMs and provides framework-specific diagnostic commands.

N+1 Query Detector Data Schema & Taxonomy

The N+1 Query Detector organizes its analysis into structured reports for clear prioritization.

Section Description
Summary Aggregated stats of files scanned and total patterns identified.
Critical Issues High-priority bottlenecks located in specific files with line numbers.
Fix Logic Recommended code changes like eager loading or batching.
Impact Metric Comparative analysis showing expected query reduction after optimization.

All metadata regarding detected ORMs and query patterns is preserved to facilitate multi-agent support and automated benchmarking.

N+1 Query Detector Advanced Features

  • Query Count Guards: Generates custom middleware to monitor and alert when a request exceeds a specific query threshold.
  • SQL Normalization: Groups similar queries by replacing dynamic IDs with placeholders to identify repeated patterns accurately.
  • Framework-Specific Fixes: Provides tailored code snippets for Django, Prisma, ActiveRecord, and GORM to ensure high-quality recommendations.
  • Performance Benchmarking: Includes utilities to measure database load and response time improvements before and after applying fixes within Openclaw Skills.

SKILL.md


Loading

Related Openclaw Skills

METADATA

Github Stars: 0
forks: 0

Featured*