Skip to content

fix: correct example to raise n+1 error#13

Merged
JacobCoffee merged 3 commits intoJacobCoffee:mainfrom
cofin:feat/stuff
Nov 30, 2025
Merged

fix: correct example to raise n+1 error#13
JacobCoffee merged 3 commits intoJacobCoffee:mainfrom
cofin:feat/stuff

Conversation

@cofin
Copy link
Contributor

@cofin cofin commented Nov 29, 2025

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.

Copilot AI review requested due to automatic review settings November 29, 2025 21:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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" and lazy="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
Copilot AI review requested due to automatic review settings November 30, 2025 01:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@JacobCoffee JacobCoffee merged commit f6ae942 into JacobCoffee:main Nov 30, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants