Skip to content

fix: eager load Position and TelegramUser to eliminate N+1 queries in…#153

Open
chuks68 wants to merge 1 commit into
Quantarq:mainfrom
chuks68:fix/eager-load-notifications
Open

fix: eager load Position and TelegramUser to eliminate N+1 queries in…#153
chuks68 wants to merge 1 commit into
Quantarq:mainfrom
chuks68:fix/eager-load-notifications

Conversation

@chuks68

@chuks68 chuks68 commented Jun 20, 2026

Copy link
Copy Markdown

this pr closes #65 This PR resolves the N+1 query issue in UserDBConnector.get_users_for_notifications by eager loading the related Position and TelegramUser entities using SQLAlchemy's joinedload.
Configured positions and telegram_user relationships on the User model.
Updated the query in get_users_for_notifications to apply .options(joinedload(User.positions), joinedload(User.telegram_user)).
Re-mapped query outputs to return the expected (contract_address, telegram_id) tuple type to preserve the existing signature and behavior.

@YaronZaki YaronZaki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Love the joinedload fix — clean way to kill the N+1. CI is failing on the test job though, so please address that and push a fix before we can land this.

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.

perf: Fix N+1 queries in get_users_for_notifications() with eager loading

2 participants