Session and user caching

This commit is contained in:
admin 2021-01-26 23:33:22 +00:00
parent 21096c523d
commit 132c46ac9a
3 changed files with 10 additions and 4 deletions

View File

@ -63,7 +63,10 @@ class Api::BaseController < ApplicationController
end
def current_resource_owner
@current_user ||= User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token
@current_user ||= Rails.cache.fetch("dk:user:#{doorkeeper_token.resource_owner_id}", expires_in: 25.hours) do
User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token
end
#@current_user ||= User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token
end
def current_user

View File

@ -94,7 +94,9 @@ class ApplicationController < ActionController::Base
end
def current_session
@current_session ||= SessionActivation.find_by(session_id: cookies.signed['_session_id'])
@current_session ||= Rails.cache.fetch("dk:sess:#{cookies.signed['_session_id']}", expires_in: 25.hours) do
SessionActivation.find_by(session_id: cookies.signed['_session_id'])
end
end
def cache_collection(raw, klass)

View File

@ -43,7 +43,7 @@ module GabSocial
module MigrationHelpers
# Stub for Database.postgresql? from GitLab
def self.postgresql?
ActiveRecord::Base.configurations[Rails.env]['adapter'].casecmp('postgresql').zero?
ActiveRecord::Base.configurations[Rails.env]['adapter'].casecmp('postgresql_makara').zero?
end
# Stub for Database.mysql? from GitLab
@ -57,7 +57,8 @@ module GabSocial
if GabSocial::MigrationHelpers.postgresql?
'information_schema.role_table_grants'
else
'mysql.user'
'information_schema.role_table_grants'
#'mysql.user'
end
def self.scope_to_current_user