I know every request to a Rails app instantiates a new controller for the request, so the controller itself is thread safe.
So, if I make a request to /users
, the UsersController
for example will be a new instance.
However, UsersController
inherits from ApplicationController
and my ApplicationController
is something like this:
class ApplicationController < ActionController::Base
before_action :authenticate_user!
def authenticate_user!
# example
end
include CurrentUserHelper
end
This is my CurrentUserHelper:
module CurrentUserHelper
def current_user
return @current_user if @current_user
@current_user = #logic to set current user
end
class UserNotFound < StandardError
end
end
Since I use an instance variable in the CurrentUserHelper
I'm not sure if it is thread safe since I don't know if it is a new instance of the module for every request. I ask because my web server is Puma
and I want multiple threads.