diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 27b49e1b3cfbc629f6ae203f46e5296c8756609f..09af5b941647a5421b06283eced3c0a9366743d3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,7 +1,7 @@ class ApplicationController < ActionController::Base before_filter :authenticate_user! before_filter :reject_blocked! - before_filter :set_current_user_for_observers + before_filter :set_current_user_for_thread before_filter :add_abilities before_filter :dev_tools if Rails.env == 'development' before_filter :default_headers @@ -47,9 +47,8 @@ class ApplicationController < ActionController::Base end end - def set_current_user_for_observers - MergeRequestObserver.current_user = current_user - IssueObserver.current_user = current_user + def set_current_user_for_thread + Thread.current[:current_user] = current_user end def abilities diff --git a/app/observers/base_observer.rb b/app/observers/base_observer.rb index 182d3b7b73c96954992b64f54e2601c33fd4e5c6..92b73981d27cc89cda9dae0fdd741ddfa67397da 100644 --- a/app/observers/base_observer.rb +++ b/app/observers/base_observer.rb @@ -6,4 +6,8 @@ class BaseObserver < ActiveRecord::Observer def log_info message Gitlab::AppLogger.info message end + + def current_user + Thread.current[:current_user] + end end diff --git a/app/observers/issue_observer.rb b/app/observers/issue_observer.rb index 03ce4b95ac8c754c21befc4ad19103e8315ec535..888fa7f6b734ef20fa033f7b43bb1fdbbf61d2f0 100644 --- a/app/observers/issue_observer.rb +++ b/app/observers/issue_observer.rb @@ -1,6 +1,4 @@ class IssueObserver < BaseObserver - cattr_accessor :current_user - def after_create(issue) notification.new_issue(issue, current_user) end diff --git a/app/observers/merge_request_observer.rb b/app/observers/merge_request_observer.rb index d0dfad8869da835426a412a7ffdcbd241b8d6203..03d4a22c1e64433304f16ce3191a2d1421e5f94b 100644 --- a/app/observers/merge_request_observer.rb +++ b/app/observers/merge_request_observer.rb @@ -1,6 +1,4 @@ class MergeRequestObserver < BaseObserver - cattr_accessor :current_user - def after_create(merge_request) notification.new_merge_request(merge_request, current_user) end diff --git a/config/database.yml.mysql b/config/database.yml.mysql index 436bea77f0f349fe7fd8a4d3c80469cd427d65d8..a3eff1a74f8a5b4fa8acc57994371b3f6bcac0e8 100644 --- a/config/database.yml.mysql +++ b/config/database.yml.mysql @@ -6,7 +6,7 @@ production: encoding: utf8 reconnect: false database: gitlabhq_production - pool: 5 + pool: 10 username: root password: "secure password" # host: localhost diff --git a/config/database.yml.postgresql b/config/database.yml.postgresql index 4a4aa3465a6c190377143089fb3fef3c90bc50f1..4b74f3348f8a3a54baeb9df9c53d34926c3e7a9a 100644 --- a/config/database.yml.postgresql +++ b/config/database.yml.postgresql @@ -5,7 +5,7 @@ production: adapter: postgresql encoding: unicode database: gitlabhq_production - pool: 5 + pool: 10 username: git password: # host: localhost diff --git a/config/environments/production.rb b/config/environments/production.rb index dc8e25593aee7654481a849844c3052ed0e6c041..183b7ae5b70924086d76ccdfe0927a2654d322c9 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -52,7 +52,7 @@ Gitlab::Application.configure do # config.action_mailer.raise_delivery_errors = false # Enable threaded mode - # config.threadsafe! + config.threadsafe! # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation can not be found) diff --git a/config/initializers/2_app.rb b/config/initializers/2_app.rb index 27a0c0ffeb2cdd4a603e54f28a97f563c7059bd5..e2f98002347b03246473322d827398b659b06b74 100644 --- a/config/initializers/2_app.rb +++ b/config/initializers/2_app.rb @@ -6,3 +6,8 @@ module Gitlab Settings end end + +# +# Load all libs for threadsafety +# +Dir["#{Rails.root}/lib/**/*.rb"].each { |file| require file } diff --git a/lib/api/issues.rb b/lib/api/issues.rb index a2983e197e7175522634714004909fad7b77e738..a15203d1563b3eb21ed55184c4f54adfc18b8ef3 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -2,6 +2,7 @@ module API # Issues API class Issues < Grape::API before { authenticate! } + before { Thread.current[:current_user] = current_user } resource :issues do # Get currently authenticated user's issues @@ -79,7 +80,7 @@ module API attrs = attributes_for_keys [:title, :description, :assignee_id, :milestone_id, :state_event] attrs[:label_list] = params[:labels] if params[:labels].present? - IssueObserver.current_user = current_user + if @issue.update_attributes attrs present @issue, with: Entities::Issue else diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb index 23e2f82889fc668f5187d626cce3c40117c9bcdb..861a4f4d15941ac01d9a6b39c9a49eecf96411a2 100644 --- a/lib/api/merge_requests.rb +++ b/lib/api/merge_requests.rb @@ -2,6 +2,7 @@ module API # MergeRequest API class MergeRequests < Grape::API before { authenticate! } + before { Thread.current[:current_user] = current_user } resource :projects do helpers do @@ -94,8 +95,6 @@ module API authorize! :modify_merge_request, merge_request - MergeRequestObserver.current_user = current_user - if merge_request.update_attributes attrs merge_request.reload_code merge_request.mark_as_unchecked diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb index efab5510c5961ed463599e0ee177c39610c37ae8..d2819b7c1d614004a800d671bce186c179ee3ec2 100644 --- a/spec/models/milestone_spec.rb +++ b/spec/models/milestone_spec.rb @@ -39,7 +39,6 @@ describe Milestone do end it "should count closed issues" do - IssueObserver.current_user = issue.author issue.close milestone.issues << issue milestone.percent_complete.should == 100