Wheels Refactoring

Refactor CFWheels code to prevent SQL injection and optimize N+1 queries.

203|108|Updated Jan 13, 2011
One-click install
npx skills add https://github.com/wheels-dev/wheels --skill wheels-refactoring
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Wheels Refactoring
Source: https://github.com/wheels-dev/wheels/tree/main/.claude/skills/wheels-refactoring
Command: npx skills add https://github.com/wheels-dev/wheels --skill wheels-refactoring

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill guides developers in refactoring CFWheels code to significantly improve performance, enhance security, and increase maintainability. It provides clear patterns and best practices to address common anti-patterns like N+1 queries and insecure parameter handling.

Core Features & Use Cases

  • Performance Optimization: Provides patterns for solving N+1 query problems and implementing eager loading to reduce database calls.
  • Security Enhancement: Guides on parameter verification and SQL injection prevention to harden your application.
  • Code Quality Improvement: Offers strategies like "Extract Method" to clean up complex functions and improve readability.
  • Use Case: Your posts index page is slow due to N+1 queries. This skill shows you how to refactor your findAll() call to findAll(include="user"), drastically reducing database calls and speeding up your page, allowing users to rest while your AI works.

Quick Start

Before (N+1 query):

<cfloop query="posts">

<p>#posts.user().name#</p>

</cfloop>

After (Eager loading):

posts = model("Post").findAll(include="user");

<cfloop query="posts">

<p>#posts.userName#</p>

</cfloop>

Frequently Asked Questions about Wheels Refactoring

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

FAQPage Schema
How do I fix N+1 query problems in CFWheels?

N+1 query problems occur when loops trigger separate database calls for each record. Refactor by using eager loading with `findAll(include="relationName")` to fetch related data in a single query, dramatically reducing database calls and improving page load times.

What's the best way to prevent SQL injection in ColdFusion Wheels code?

SQL injection prevention in Wheels requires parameter verification and safe query construction. Use parameterized queries and automatic escaping through the framework's built-in methods rather than string concatenation to harden your application against malicious input.

How do I refactor slow Wheels code to improve performance?

Refactor slow Wheels code by addressing N+1 queries through eager loading, extracting complex functions into smaller methods for clarity, and optimizing query patterns. These changes reduce database calls, improve readability, and increase overall application speed.

Can I use eager loading with related objects in CFWheels?

Yes. CFWheels supports eager loading through the `include` parameter in query methods like `findAll(include="user")`. This loads associated records upfront rather than lazily, eliminating separate queries for each related object and improving performance significantly.

What security hardening techniques apply to Wheels applications?

Security hardening for Wheels includes parameter verification to validate input, SQL injection prevention through parameterization, and modularization via Extract Method patterns. These practices protect against common vulnerabilities while maintaining code maintainability.

When should I refactor my Wheels code for security and performance?

Refactor your Wheels code when you encounter performance bottlenecks like slow index pages, detect N+1 query patterns, or identify unverified parameters that could introduce SQL injection risks. Early refactoring prevents technical debt and security vulnerabilities.