Skip to content

Commit

Permalink
perf: cache user by username for current user
Browse files Browse the repository at this point in the history
  • Loading branch information
macite committed Jan 13, 2022
1 parent 349f1f3 commit 8ae92d5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/helpers/authentication_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ def authenticated?
# Get the current user either from warden or from the header
#
def current_user
User.find_by_username(headers['Username']) || User.find_by_username(params['username'])
username = headers['Username'] || params['username']
Rails.cache.fetch("user/#{username}", expires_in: 1.hours) do
User.find_by_username(username)
end
end

#
Expand Down
1 change: 1 addition & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@

require_relative 'doubtfire_logger'
config.logger = DoubtfireLogger.logger
Rails.logger = DoubtfireLogger.logger

config.active_record.encryption.key_derivation_salt = ENV['DF_ENCRYPTION_KEY_DERIVATION_SALT'] || 'U9jurHMfZbMpzlbDTMe5OSAhUJYHla9Z'
config.active_record.encryption.deterministic_key = ENV['DF_ENCRYPTION_KEY_DERIVATION_SALT'] || 'zYtzYUlLFaWdvdUO5eIINRT6ZKDddcgx'
Expand Down

0 comments on commit 8ae92d5

Please sign in to comment.