If session[:current_account_id] is nil, current_account will make a useless database query each time it is called. This would happen if you are calling current_account on a public page while a user has yet to log in.

The above code will only evaluate @current_account if session[:current_account_id] has been set, otherwise it will return nil without hitting the database. Once session[:current_account_id] is set, it will hit the database a single time, memoize the result in @current_account, and return @current_account for the duration of the Rails request cycle. This should help take some load off the database.

If anyone has an even simpler solution, please let me know in the comments!