diff --git a/app/models/user_auth_token.rb b/app/models/user_auth_token.rb index 97eb0372ff7..14be316e2a9 100644 --- a/app/models/user_auth_token.rb +++ b/app/models/user_auth_token.rb @@ -122,13 +122,19 @@ class UserAuthToken < ActiveRecord::Base expire_before = SiteSetting.maximum_session_age.hours.ago user_token = - find_by( + where( "(auth_token = :token OR prev_auth_token = :token) AND rotated_at > :expire_before", token: token, expire_before: expire_before, ) + if SiteSetting.verbose_auth_token_logging && path = opts.dig(:path) + user_token = user_token.annotate("path:#{path}") + end + + user_token = user_token.first + if !user_token log_verbose( action: "miss token", diff --git a/config/environments/test.rb b/config/environments/test.rb index 370404eb11a..cb3edca1239 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -53,6 +53,16 @@ Discourse::Application.configure do config.active_record.verbose_query_logs = true config.active_record.query_log_tags_enabled = true + config.active_record.query_log_tags = [ + :application, + :controller, + :action, + { + request_path: ->(context) { context[:controller]&.request&.path }, + thread_id: ->(context) { Thread.current.object_id }, + }, + ] + config.after_initialize do ActiveRecord::LogSubscriber.backtrace_cleaner.add_silencer do |line| line =~ %r{lib/freedom_patches}