summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-06-11 15:54:15 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-06-11 15:54:15 +0000
commit964f7a1196c56a100242525eb3b8a4b69118d2ff (patch)
tree23762152264492821c01c9124802d9d6c4384d11
parent159eee8dfde049b571172ee3594cf8c920b0fc10 (diff)
parent993af5d0d2d596040195c4109c531c33deeac026 (diff)
downloadgitlab-ce-964f7a1196c56a100242525eb3b8a4b69118d2ff.tar.gz
Merge branch 'feature/threadsafe' of /home/git/repositories/gitlab/gitlabhq
-rw-r--r--app/controllers/application_controller.rb7
-rw-r--r--app/observers/base_observer.rb4
-rw-r--r--app/observers/issue_observer.rb2
-rw-r--r--app/observers/merge_request_observer.rb2
-rw-r--r--config/database.yml.mysql2
-rw-r--r--config/database.yml.postgresql2
-rw-r--r--config/environments/production.rb2
-rw-r--r--config/initializers/2_app.rb5
-rw-r--r--lib/api/issues.rb3
-rw-r--r--lib/api/merge_requests.rb3
-rw-r--r--spec/models/milestone_spec.rb1
11 files changed, 18 insertions, 15 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 27b49e1b3cf..09af5b94164 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 182d3b7b73c..92b73981d27 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 03ce4b95ac8..888fa7f6b73 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 d0dfad8869d..03d4a22c1e6 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 436bea77f0f..a3eff1a74f8 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 4a4aa3465a6..4b74f3348f8 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 dc8e25593ae..183b7ae5b70 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 27a0c0ffeb2..e2f98002347 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 a2983e197e7..a15203d1563 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 23e2f82889f..861a4f4d159 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 efab5510c59..d2819b7c1d6 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