askill
ln-812-query-optimizer

ln-812-query-optimizerSafety 88Repository

Fixes N+1 queries, redundant fetches, over-fetching with keep/discard verification

207 stars
4.1k downloads
Updated 3/14/2026

Package Files

Loading files...
SKILL.md

Paths: File paths (shared/, references/, ../ln-*) are relative to skills repo root. If not found at CWD, locate this SKILL.md directory and go up one level for repo root.

ln-812-query-optimizer

Type: L3 Worker Category: 8XX Optimization Parent: ln-810-performance-optimization-coordinator

Fixes query efficiency issues found by ln-651-query-efficiency-auditor. Each fix verified via tests with keep/discard pattern. Metric: query count reduction (not runtime benchmark).


Overview

AspectDetails
InputAudit findings from docs/project/persistence_audit.md (ln-651 section) OR target file
OutputOptimized queries, verification report
Companionln-651-query-efficiency-auditor (finds issues) → ln-812 (fixes them)

Workflow

Phases: Pre-flight → Load Findings → Prioritize → Fix Loop → Report


Phase 0: Pre-flight Checks

CheckRequiredAction if Missing
Audit findings OR target fileYesBlock optimization
Test infrastructureYesBlock (need tests for verification)
Git clean stateYesBlock (need clean baseline for revert)

MANDATORY READ: Load shared/references/ci_tool_detection.md — use Test Frameworks section for test detection.

Worktree & Branch Isolation

MANDATORY READ: Load shared/references/git_worktree_fallback.md — use ln-812 row.


Phase 1: Load Findings

From Audit Report

Read docs/project/persistence_audit.md, extract ln-651 findings:

Finding TypeOptimization
N+1 queryBatch loading / eager loading / .Include() / prefetch_related
Redundant fetchPass object instead of ID, cache result
Over-fetchingSelect specific fields / projection / .Select()
Missing index hintAdd index annotation / migration
Unbounded queryAdd .Take() / LIMIT / pagination

From Target File

If no audit report: scan target file for query patterns matching the table above.


Phase 2: Prioritize Fixes

PriorityCriteria
1 (highest)N+1 in hot path (called per request)
2Redundant fetches (same entity loaded multiple times)
3Over-fetching (SELECT * where few columns needed)
4Missing pagination on user-facing endpoints

Phase 3: Fix Loop (Keep/Discard)

Per-Fix Cycle

FOR each finding (F1..FN):
  1. APPLY: Edit query code (surgical change)
  2. VERIFY: Run tests
     IF tests FAIL → DISCARD (revert) → next finding
  3. VERIFY: Tests PASS → KEEP
  4. LOG: Record fix for report

Keep/Discard Decision

ConditionDecision
No tests cover affected file/functionSKIP finding — log as "uncovered, skipped"
Tests passKEEP
Tests failDISCARD + log failure reason
Fix introduces new N+1DISCARD

Note: No benchmark needed — query optimization metric is correctness (tests pass) + structural improvement (fewer queries). The audit already identified the inefficiency.


Phase 4: Report Results

Report Schema

FieldDescription
sourceAudit report path or target file
findings_totalTotal findings from audit
fixes_appliedSuccessfully kept fixes
fixes_discardedFailed fixes with reasons
fix_details[]Per-fix: finding type, file, before/after description

Configuration

Options:
  # Source
  audit_report: "docs/project/persistence_audit.md"
  target_file: ""               # Alternative to audit report

  # Verification
  run_tests: true

  # Scope
  fix_types:                    # Filter which types to fix
    - n_plus_one
    - redundant_fetch
    - over_fetching
    - unbounded_query

Error Handling

ErrorCauseSolution
No audit findingsln-651 not run or no issuesReport "no findings to optimize"
ORM-specific syntaxUnknown ORMQuery Context7/Ref for ORM docs
Migration neededIndex addition requires migrationLog as manual step, skip

References

  • ../ln-651-query-efficiency-auditor/SKILL.md (companion: finds issues)
  • shared/references/ci_tool_detection.md (test detection)

Definition of Done

  • Findings loaded from audit report or target file scan
  • Fixes prioritized (N+1 first, then redundant, over-fetch, unbounded)
  • Each fix applied with keep/discard: tests pass → keep, tests fail → discard
  • No new query inefficiencies introduced by fixes
  • Report returned with findings total, fixes applied, fixes discarded

Version: 1.0.0 Last Updated: 2026-03-08

Install

Download ZIP
Requires askill CLI v1.0+

AI Quality Score

78/100Analyzed 3/27/2026

Well-structured L3 skill for query optimization with clear phase-based workflow and keep/discard verification pattern. Technical content is accurate and broadly applicable (N+1, over-fetching, eager loading patterns) though file naming and internal cross-references suggest repo-specific context. Strong safety mechanisms (pre-flight checks, test verification) and good clarity through tables and structured phases. Missing concrete code examples reduces actionability slightly.

88
85
80
82
76

Metadata

Licenseunknown
Version-
Updated3/14/2026
Publisherlevnikolaevich

Tags

github-actionsobservabilitytesting