BigW Consortium Gitlab

Commit 964f7a11 by Dmitriy Zaporozhets

Merge branch 'feature/threadsafe' of /home/git/repositories/gitlab/gitlabhq

parents 159eee8d 993af5d0
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
before_filter :authenticate_user! before_filter :authenticate_user!
before_filter :reject_blocked! before_filter :reject_blocked!
before_filter :set_current_user_for_observers before_filter :set_current_user_for_thread
before_filter :add_abilities before_filter :add_abilities
before_filter :dev_tools if Rails.env == 'development' before_filter :dev_tools if Rails.env == 'development'
before_filter :default_headers before_filter :default_headers
...@@ -47,9 +47,8 @@ class ApplicationController < ActionController::Base ...@@ -47,9 +47,8 @@ class ApplicationController < ActionController::Base
end end
end end
def set_current_user_for_observers def set_current_user_for_thread
MergeRequestObserver.current_user = current_user Thread.current[:current_user] = current_user
IssueObserver.current_user = current_user
end end
def abilities def abilities
......
...@@ -6,4 +6,8 @@ class BaseObserver < ActiveRecord::Observer ...@@ -6,4 +6,8 @@ class BaseObserver < ActiveRecord::Observer
def log_info message def log_info message
Gitlab::AppLogger.info message Gitlab::AppLogger.info message
end end
def current_user
Thread.current[:current_user]
end
end end
class IssueObserver < BaseObserver class IssueObserver < BaseObserver
cattr_accessor :current_user
def after_create(issue) def after_create(issue)
notification.new_issue(issue, current_user) notification.new_issue(issue, current_user)
end end
......
class MergeRequestObserver < BaseObserver class MergeRequestObserver < BaseObserver
cattr_accessor :current_user
def after_create(merge_request) def after_create(merge_request)
notification.new_merge_request(merge_request, current_user) notification.new_merge_request(merge_request, current_user)
end end
......
...@@ -6,7 +6,7 @@ production: ...@@ -6,7 +6,7 @@ production:
encoding: utf8 encoding: utf8
reconnect: false reconnect: false
database: gitlabhq_production database: gitlabhq_production
pool: 5 pool: 10
username: root username: root
password: "secure password" password: "secure password"
# host: localhost # host: localhost
......
...@@ -5,7 +5,7 @@ production: ...@@ -5,7 +5,7 @@ production:
adapter: postgresql adapter: postgresql
encoding: unicode encoding: unicode
database: gitlabhq_production database: gitlabhq_production
pool: 5 pool: 10
username: git username: git
password: password:
# host: localhost # host: localhost
......
...@@ -52,7 +52,7 @@ Gitlab::Application.configure do ...@@ -52,7 +52,7 @@ Gitlab::Application.configure do
# config.action_mailer.raise_delivery_errors = false # config.action_mailer.raise_delivery_errors = false
# Enable threaded mode # Enable threaded mode
# config.threadsafe! config.threadsafe!
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found) # the I18n.default_locale when a translation can not be found)
......
...@@ -6,3 +6,8 @@ module Gitlab ...@@ -6,3 +6,8 @@ module Gitlab
Settings Settings
end end
end end
#
# Load all libs for threadsafety
#
Dir["#{Rails.root}/lib/**/*.rb"].each { |file| require file }
...@@ -2,6 +2,7 @@ module API ...@@ -2,6 +2,7 @@ module API
# Issues API # Issues API
class Issues < Grape::API class Issues < Grape::API
before { authenticate! } before { authenticate! }
before { Thread.current[:current_user] = current_user }
resource :issues do resource :issues do
# Get currently authenticated user's issues # Get currently authenticated user's issues
...@@ -79,7 +80,7 @@ module API ...@@ -79,7 +80,7 @@ module API
attrs = attributes_for_keys [:title, :description, :assignee_id, :milestone_id, :state_event] attrs = attributes_for_keys [:title, :description, :assignee_id, :milestone_id, :state_event]
attrs[:label_list] = params[:labels] if params[:labels].present? attrs[:label_list] = params[:labels] if params[:labels].present?
IssueObserver.current_user = current_user
if @issue.update_attributes attrs if @issue.update_attributes attrs
present @issue, with: Entities::Issue present @issue, with: Entities::Issue
else else
......
...@@ -2,6 +2,7 @@ module API ...@@ -2,6 +2,7 @@ module API
# MergeRequest API # MergeRequest API
class MergeRequests < Grape::API class MergeRequests < Grape::API
before { authenticate! } before { authenticate! }
before { Thread.current[:current_user] = current_user }
resource :projects do resource :projects do
helpers do helpers do
...@@ -94,8 +95,6 @@ module API ...@@ -94,8 +95,6 @@ module API
authorize! :modify_merge_request, merge_request authorize! :modify_merge_request, merge_request
MergeRequestObserver.current_user = current_user
if merge_request.update_attributes attrs if merge_request.update_attributes attrs
merge_request.reload_code merge_request.reload_code
merge_request.mark_as_unchecked merge_request.mark_as_unchecked
......
...@@ -39,7 +39,6 @@ describe Milestone do ...@@ -39,7 +39,6 @@ describe Milestone do
end end
it "should count closed issues" do it "should count closed issues" do
IssueObserver.current_user = issue.author
issue.close issue.close
milestone.issues << issue milestone.issues << issue
milestone.percent_complete.should == 100 milestone.percent_complete.should == 100
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment