Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gem querying database twice for authenticating user #788

Closed
rajeevriitm opened this issue Dec 8, 2016 · 1 comment
Closed

Gem querying database twice for authenticating user #788

rajeevriitm opened this issue Dec 8, 2016 · 1 comment

Comments

@rajeevriitm
Copy link

I am using devise token auth gem in my Rails 5 API for authentication.

class V1::HuntsController < V1::MainController
  include DeviseTokenAuth::Concerns::SetUserByToken
  before_action :authenticate_user!
  def index
  end
end

But when I look at my logs, I see that there is two database queries to find the user. One from before_action :authenticate_user and the other from update_auth_header from after_action added by DeviseTokenAuth module.

Started POST "/v1/hunts" for 192.168.0.103 at 2016-12-07 15:41:03 +0530
Processing by V1::HuntsController#create as JSON
  Parameters: {"title"=>"dddd", "clue"=>"dd", "hunt"=>{"title"=>"dddd", "clue"=>"dd"}}
  User Load (0.2ms)  SELECT  "users".* FROM "users" WHERE "users"."uid" = ? LIMIT ?  [["uid", "[email protected]"], ["LIMIT", 1]]
  User Load (0.2ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ? LIMIT ?  [["id", 15], ["LIMIT", 1]]
   (0.1ms)  begin transaction
   (0.0ms)  commit transaction
Completed 204 No Content in 102ms (ActiveRecord: 1.0ms)

Why is it firing another database query for user when current_user is already available? The database query doesnt seem to be cached also as it takes the same time to load.

I doubt if this is due to the default behavior in which token changes with each request. I have disabled this in my configuration.

@zachfeldman
Copy link
Contributor

Hi there @rajeevriitm ,

In an effort to cleanup this project and prioritize a bit, we're marking issues that haven't had any activity in a while with a "close-in-7-days" label. If we don't hear from you in about a week, we'll be closing this issue. Obviously feel free to re-open it at any time if it's the right time or this was done in error!

If you are still having the issue (especially if it's a bug report) please refer to our new Issue Template to provide some more details to help us solve it.

Hope all is well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants