forked from Gitlink/forgeplus
fixed user cache
This commit is contained in:
parent
2457e4a6ad
commit
bc836e5a1c
|
|
@ -379,7 +379,9 @@ class ApplicationController < ActionController::Base
|
|||
uid_logger("user setup start: autologin_user is #{autologin_user}")
|
||||
# 多浏览器退出账号时,token不存在处理
|
||||
if current_domain_session && autologin_user.nil?
|
||||
autologin_user = (User.active.find(current_domain_session) rescue nil)
|
||||
autologin_user = Rails.cache.fetch("ApplicationController::find_current_user:#{current_domain_session}", expires_in: 30.minutes) do
|
||||
(User.active.find(current_domain_session) rescue nil)
|
||||
end
|
||||
set_autologin_cookie(autologin_user) if autologin_user.present?
|
||||
end
|
||||
autologin_user
|
||||
|
|
|
|||
|
|
@ -27,7 +27,9 @@ module LaboratoryHelper
|
|||
end
|
||||
|
||||
def default_yun_session
|
||||
laboratory ||= (Laboratory.find_by_subdomain(request.subdomain) || Laboratory.find(1))
|
||||
laboratory ||= Rails.cache.fetch("LaboratoryHelper::default_yun_session:#{request.subdomain}:1") do
|
||||
(Laboratory.find_by_subdomain(request.subdomain) || Laboratory.find(1))
|
||||
end
|
||||
@_default_yun_session = "#{laboratory.try(:identifier).split('.').first}_user_id"
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -725,7 +725,9 @@ class UsersController < ApplicationController
|
|||
|
||||
private
|
||||
def load_user
|
||||
@user = User.find_by_login(params[:id]) || User.find_by(id: params[:id])
|
||||
@user = Rails.cache.fetch("UsersControllers::load_user:#{params[:id]}") do
|
||||
User.find_by_login(params[:id]) || User.find_by(id: params[:id])
|
||||
end
|
||||
clear_user_cookie unless @user.present?
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: tokens
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# user_id :integer default("0"), not null
|
||||
# action :string(30) default(""), not null
|
||||
# value :string(40) default(""), not null
|
||||
# created_on :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_tokens_on_user_id (user_id)
|
||||
# tokens_value (value) UNIQUE
|
||||
#
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: tokens
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# user_id :integer default("0"), not null
|
||||
# action :string(30) default(""), not null
|
||||
# value :string(40) default(""), not null
|
||||
# created_on :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_tokens_on_user_id (user_id)
|
||||
# tokens_value (value) UNIQUE
|
||||
#
|
||||
|
||||
|
||||
|
||||
#
|
||||
|
|
@ -50,13 +50,17 @@ class Token < ActiveRecord::Base
|
|||
token = Token.create(:user => user, :action => type)
|
||||
Rails.logger.info "###### Token.get_token_from_user is nul and agine create token: #{token&.value}"
|
||||
else
|
||||
token.update_attribute(:created_on, Time.now)
|
||||
Rails.cache.fetch("user::update::created_on::#{user.id}",:expires_in => 10.minutes) do
|
||||
token.update_attribute(:created_on, Time.now)
|
||||
end
|
||||
end
|
||||
token
|
||||
end
|
||||
|
||||
def self.get_token_from_user(user, action)
|
||||
token = Token.where(:action => action, :user_id => user).first
|
||||
token = Rails.cache.fetch("Token::get_token_from_user:#{user.id}:1", :expires_in => 10.minutes) do
|
||||
Token.where(:action => action, :user_id => user).first
|
||||
end
|
||||
Rails.logger.info "###### self.get_token_from_user query result: #{token&.value}"
|
||||
unless token
|
||||
token = Token.create!(user_id: user.id, action: action)
|
||||
|
|
|
|||
Loading…
Reference in New Issue