Currently, some people (myself included) are experiencing long sign in times, which usually end up timing out, thus preventing people from signing in.
Looking at Skylight we can see that the requests take on average 2.7 seconds. Looking deeper in the #github or #twitter actions we can see that there are a lot of repeated queries:

This can definitely be refactored and the amount of queries can be reduced. The main -- and probably only -- file that needs to be refactored is the authorization_service.rb file.
Of course, this should be approached with care, as this affects how people authorize themselves into the app. The sign in process should still work, and refactoring shouldn't cause any weird data leakage (probably hard to accomplish, but good to keep it in mind).
I did research on this issue and found out that most of these queries are for validations (e.g. uniqueness validations) and callbacks. I think we could optimize it by only performing validations when the corresponding field was changed + adding unique indexes to the database if they are missing.
There were even attempts to bring such behavior into rails, but there's no visible result:
https://github.com/rails/rails/pull/30988
https://github.com/rails/rails/issues/34281
Did a little investigation with this when trying to solve something else. Turns out user.remember_me! runs user.save in the background (therefore another query).
The existence of the the remember_me! and the remember_me = true and the multiple saves are all symptoms of hacked on functionality to make sure users stay signed in appropriately.
I eventually left this in and moved on.
So this can definitely be replaced by alternate functionality to keep the session "remembered".
Most helpful comment
I did research on this issue and found out that most of these queries are for validations (e.g. uniqueness validations) and callbacks. I think we could optimize it by only performing validations when the corresponding field was changed + adding unique indexes to the database if they are missing.
There were even attempts to bring such behavior into rails, but there's no visible result:
https://github.com/rails/rails/pull/30988
https://github.com/rails/rails/issues/34281