Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize DB accesses by using an SQL JOIN when retrieving a user.
`Datastore.find_user()` is used on every page load to verify the user in the current session; until now, `find_user()` would trigger 2+ DB accesses, since the `roles` relationship uses lazy loading by default. This is useful to reduce the rows accessed when retrieving multiple users from the DB. However, in `find_user()` we always retrieve only one, so it makes sense to retrieve all roles in one SQL operation instead of always triggering 2 or more. This would be unnecessary if the `roles` relationship was defined with `lazy="joined"`. However, that would greatly increase the number of rows accessed on all queries (even when querying all users), so I think it's better to be selective and optimize only these accesses which happen on every page load.
- Loading branch information