fix: correct example to raise n+1 error#13
Conversation
There was a problem hiding this comment.
Pull request overview
This PR modifies the Litestar + Advanced-Alchemy example to properly demonstrate N+1 query detection by removing eager loading configurations. The changes intentionally introduce lazy loading behavior that will trigger N+1 queries when relationships are accessed, allowing the debug toolbar's SQLAlchemy panel to detect and alert on this common performance issue.
Key Changes:
- Removed eager loading strategies (
lazy="selectin"andlazy="joined") from SQLAlchemy relationship definitions in models - Removed explicit
load=[User.posts]parameter from the users page repository query - Bumped package version from 0.1.0 to 0.2.0
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| uv.lock | Updated package version from 0.1.0 to 0.2.0 to reflect the changes |
| examples/litestar_advanced_alchemy/models.py | Removed lazy loading strategies from User.posts and Post.author relationships to enable default lazy loading behavior |
| examples/litestar_advanced_alchemy/app.py | Removed load=[User.posts] parameter from users_page() to prevent eager loading, causing N+1 queries when accessing post counts |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Added review workflow documentation to ensure quality gate verification and pattern extraction. - Introduced testing workflow documentation with a focus on achieving 90%+ coverage. - Created MCP tool strategy for task-based tool selection and complexity-based decision making. - Developed skills documentation for Advanced-Alchemy, Litestar, and Pytest, detailing patterns and usage. - Established a pattern library with reusable patterns and guidelines for implementation. - Defined quality gates in YAML format to enforce coding standards and testing requirements. - Updated CLAUDE.md with AI agent guidelines, project structure, and development workflows. - Added .gitkeep files to maintain directory structure for active, archive, examples, and patterns.
- Documented research objectives and analysis of existing panel implementations - Outlined middleware integration strategy for WebSocket support - Defined core data models for WebSocket message and connection tracking - Proposed memory management and testing strategies - Included UI/UX design concepts for the WebSocket panel - Established configuration options and implementation risks with mitigations - Set success criteria and next steps for development
There was a problem hiding this comment.
Copilot reviewed 47 out of 63 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This removes the settings from the model and service to cause an N+1.
This may trigger a Greenlet exception now. if that's the case, that's good - it implicitly prevents the user from doing an N+1. However, this doesn't help for sync database connections. So, for the demo we may need to add a sync service and sync route so that you can demonstrate it in the UI.