fix: eager load Position and TelegramUser to eliminate N+1 queries in…#153
fix: eager load Position and TelegramUser to eliminate N+1 queries in…#153chuks68 wants to merge 1 commit into
Conversation
… get_users_for_notifications
YaronZaki
left a comment
There was a problem hiding this comment.
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.
|
Hi @chuks68 — eager loading
This looks like a fixture-ordering issue (children being inserted before their parent |
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.