I am reading the RoR Tutorial by Micheal Hartl and trying to make my very first web application at all. Following the book, I arrived now at chapter 8. In this chapter, one defines a couple of methods in the sessions helper:
log_in(user), current_user, and logged_in
With these defined, we put an if logged_in? condition in the site header, to decide which links are displayed in the header (e.g. "login" or "logout" depending on the logged_in status).
Now with the new header, I noticed the following behaviour in the application. Whatever link I click now (even home or help page), the application tries to retrieve a user from the database (even if no user is logged in, the application still hits the database asking for user_id: NULL).
> User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT $1 [["LIMIT", 1]]
I guess that this means that current_user doesn't persist from one request to the other, which means it has to be reloaded for each new request. So my question is:
a) is that really the case?
b) isn't that negatively affecting the performance of the application if it is on a production website?
c) If the answer to b) is yes, is there a way to avoid this behaviour?