Commit 964f7a1196c56a100242525eb3b8a4b69118d2ff
Exists in
master
and in
4 other branches
Merge branch 'feature/threadsafe' of /home/git/repositories/gitlab/gitlabhq
Showing
11 changed files
with
18 additions
and
15 deletions
Show diff stats
app/controllers/application_controller.rb
| 1 | class ApplicationController < ActionController::Base | 1 | class ApplicationController < ActionController::Base |
| 2 | before_filter :authenticate_user! | 2 | before_filter :authenticate_user! |
| 3 | before_filter :reject_blocked! | 3 | before_filter :reject_blocked! |
| 4 | - before_filter :set_current_user_for_observers | 4 | + before_filter :set_current_user_for_thread |
| 5 | before_filter :add_abilities | 5 | before_filter :add_abilities |
| 6 | before_filter :dev_tools if Rails.env == 'development' | 6 | before_filter :dev_tools if Rails.env == 'development' |
| 7 | before_filter :default_headers | 7 | before_filter :default_headers |
| @@ -47,9 +47,8 @@ class ApplicationController < ActionController::Base | @@ -47,9 +47,8 @@ class ApplicationController < ActionController::Base | ||
| 47 | end | 47 | end |
| 48 | end | 48 | end |
| 49 | 49 | ||
| 50 | - def set_current_user_for_observers | ||
| 51 | - MergeRequestObserver.current_user = current_user | ||
| 52 | - IssueObserver.current_user = current_user | 50 | + def set_current_user_for_thread |
| 51 | + Thread.current[:current_user] = current_user | ||
| 53 | end | 52 | end |
| 54 | 53 | ||
| 55 | def abilities | 54 | def abilities |
app/observers/base_observer.rb
| @@ -6,4 +6,8 @@ class BaseObserver < ActiveRecord::Observer | @@ -6,4 +6,8 @@ class BaseObserver < ActiveRecord::Observer | ||
| 6 | def log_info message | 6 | def log_info message |
| 7 | Gitlab::AppLogger.info message | 7 | Gitlab::AppLogger.info message |
| 8 | end | 8 | end |
| 9 | + | ||
| 10 | + def current_user | ||
| 11 | + Thread.current[:current_user] | ||
| 12 | + end | ||
| 9 | end | 13 | end |
app/observers/issue_observer.rb
app/observers/merge_request_observer.rb
| 1 | class MergeRequestObserver < BaseObserver | 1 | class MergeRequestObserver < BaseObserver |
| 2 | - cattr_accessor :current_user | ||
| 3 | - | ||
| 4 | def after_create(merge_request) | 2 | def after_create(merge_request) |
| 5 | notification.new_merge_request(merge_request, current_user) | 3 | notification.new_merge_request(merge_request, current_user) |
| 6 | end | 4 | end |
config/database.yml.mysql
| @@ -6,7 +6,7 @@ production: | @@ -6,7 +6,7 @@ production: | ||
| 6 | encoding: utf8 | 6 | encoding: utf8 |
| 7 | reconnect: false | 7 | reconnect: false |
| 8 | database: gitlabhq_production | 8 | database: gitlabhq_production |
| 9 | - pool: 5 | 9 | + pool: 10 |
| 10 | username: root | 10 | username: root |
| 11 | password: "secure password" | 11 | password: "secure password" |
| 12 | # host: localhost | 12 | # host: localhost |
config/database.yml.postgresql
| @@ -5,7 +5,7 @@ production: | @@ -5,7 +5,7 @@ production: | ||
| 5 | adapter: postgresql | 5 | adapter: postgresql |
| 6 | encoding: unicode | 6 | encoding: unicode |
| 7 | database: gitlabhq_production | 7 | database: gitlabhq_production |
| 8 | - pool: 5 | 8 | + pool: 10 |
| 9 | username: git | 9 | username: git |
| 10 | password: | 10 | password: |
| 11 | # host: localhost | 11 | # host: localhost |
config/environments/production.rb
| @@ -52,7 +52,7 @@ Gitlab::Application.configure do | @@ -52,7 +52,7 @@ Gitlab::Application.configure do | ||
| 52 | # config.action_mailer.raise_delivery_errors = false | 52 | # config.action_mailer.raise_delivery_errors = false |
| 53 | 53 | ||
| 54 | # Enable threaded mode | 54 | # Enable threaded mode |
| 55 | - # config.threadsafe! | 55 | + config.threadsafe! |
| 56 | 56 | ||
| 57 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to | 57 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to |
| 58 | # the I18n.default_locale when a translation can not be found) | 58 | # the I18n.default_locale when a translation can not be found) |
config/initializers/2_app.rb
lib/api/issues.rb
| @@ -2,6 +2,7 @@ module API | @@ -2,6 +2,7 @@ module API | ||
| 2 | # Issues API | 2 | # Issues API |
| 3 | class Issues < Grape::API | 3 | class Issues < Grape::API |
| 4 | before { authenticate! } | 4 | before { authenticate! } |
| 5 | + before { Thread.current[:current_user] = current_user } | ||
| 5 | 6 | ||
| 6 | resource :issues do | 7 | resource :issues do |
| 7 | # Get currently authenticated user's issues | 8 | # Get currently authenticated user's issues |
| @@ -79,7 +80,7 @@ module API | @@ -79,7 +80,7 @@ module API | ||
| 79 | 80 | ||
| 80 | attrs = attributes_for_keys [:title, :description, :assignee_id, :milestone_id, :state_event] | 81 | attrs = attributes_for_keys [:title, :description, :assignee_id, :milestone_id, :state_event] |
| 81 | attrs[:label_list] = params[:labels] if params[:labels].present? | 82 | attrs[:label_list] = params[:labels] if params[:labels].present? |
| 82 | - IssueObserver.current_user = current_user | 83 | + |
| 83 | if @issue.update_attributes attrs | 84 | if @issue.update_attributes attrs |
| 84 | present @issue, with: Entities::Issue | 85 | present @issue, with: Entities::Issue |
| 85 | else | 86 | else |
lib/api/merge_requests.rb
| @@ -2,6 +2,7 @@ module API | @@ -2,6 +2,7 @@ module API | ||
| 2 | # MergeRequest API | 2 | # MergeRequest API |
| 3 | class MergeRequests < Grape::API | 3 | class MergeRequests < Grape::API |
| 4 | before { authenticate! } | 4 | before { authenticate! } |
| 5 | + before { Thread.current[:current_user] = current_user } | ||
| 5 | 6 | ||
| 6 | resource :projects do | 7 | resource :projects do |
| 7 | helpers do | 8 | helpers do |
| @@ -94,8 +95,6 @@ module API | @@ -94,8 +95,6 @@ module API | ||
| 94 | 95 | ||
| 95 | authorize! :modify_merge_request, merge_request | 96 | authorize! :modify_merge_request, merge_request |
| 96 | 97 | ||
| 97 | - MergeRequestObserver.current_user = current_user | ||
| 98 | - | ||
| 99 | if merge_request.update_attributes attrs | 98 | if merge_request.update_attributes attrs |
| 100 | merge_request.reload_code | 99 | merge_request.reload_code |
| 101 | merge_request.mark_as_unchecked | 100 | merge_request.mark_as_unchecked |
spec/models/milestone_spec.rb
| @@ -39,7 +39,6 @@ describe Milestone do | @@ -39,7 +39,6 @@ describe Milestone do | ||
| 39 | end | 39 | end |
| 40 | 40 | ||
| 41 | it "should count closed issues" do | 41 | it "should count closed issues" do |
| 42 | - IssueObserver.current_user = issue.author | ||
| 43 | issue.close | 42 | issue.close |
| 44 | milestone.issues << issue | 43 | milestone.issues << issue |
| 45 | milestone.percent_complete.should == 100 | 44 | milestone.percent_complete.should == 100 |