vendredi 22 mai 2015

ActiveRecord.establish_connection concurrency across requests

Using Rails, is this approach vulnerable to causing separate, concurrent requests to use the wrong connection/database?

 def find_user

@user= User.find_by_email(email)

unless @user
  #search non_pro database
  User.establish_connection("#{Rails.env}_non_pro".to_sym)

 @user= User.find_by_email(email)
end

ensure User.establish_connection("#{Rails.env}".to_sym) end

What I want to know is if a first request causes the connection to be established with 'non_pro', will a second separate request run the risk of incorrectly connecting to 'non_pro' if it runs while the first is connected to 'non_pro'

Aucun commentaire:

Enregistrer un commentaire