Skip to content

fix: eager load Position and TelegramUser to eliminate N+1 queries in get_users_for_notifications#2

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

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

Conversation

@chuks68

@chuks68 chuks68 commented Jun 20, 2026

Copy link
Copy Markdown
Owner

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.

  • Changes:
    • 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.
  • Impact:
    • Reduces database load from O(N) queries to a single joined query when fetching users for notification dispatches.

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.

1 participant