diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/issues_controller.rb | 19 | ||||
-rw-r--r-- | app/finders/issues_finder.rb | 1 | ||||
-rw-r--r-- | app/models/concerns/assignee_live_migration.rb | 20 | ||||
-rw-r--r-- | app/models/issue.rb | 7 | ||||
-rw-r--r-- | app/services/issues/update_service.rb | 1 |
5 files changed, 43 insertions, 5 deletions
diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb index 760ba246e3e..3b0c0c84e21 100644 --- a/app/controllers/projects/issues_controller.rb +++ b/app/controllers/projects/issues_controller.rb @@ -31,6 +31,16 @@ class Projects::IssuesController < Projects::ApplicationController @collection_type = "Issue" @issues = issues_collection @issues = @issues.page(params[:page]) + + ### Live assignee migration + results = @issues.map(&:migrate_assignee) + if results.any? + # Reload the collection + @issues = issues_collection + @issues = @issues.page(params[:page]) + end + ### + @issuable_meta_data = issuable_meta_data(@issues, @collection_type) if @issues.out_of_range? && @issues.total_pages != 0 @@ -225,8 +235,13 @@ class Projects::IssuesController < Projects::ApplicationController protected def issue - # The Sortable default scope causes performance issues when used with find_by - @noteable = @issue ||= @project.issues.where(iid: params[:id]).reorder(nil).take! + unless @issue + # The Sortable default scope causes performance issues when used with find_by + @noteable = @issue = @project.issues.where(iid: params[:id]).reorder(nil).take! + @issue.migrate_assignee + end + + @issue end alias_method :subscribable_resource, :issue alias_method :issuable, :issue diff --git a/app/finders/issues_finder.rb b/app/finders/issues_finder.rb index b4c074bc69c..cd7099c6c56 100644 --- a/app/finders/issues_finder.rb +++ b/app/finders/issues_finder.rb @@ -48,6 +48,7 @@ class IssuesFinder < IssuableFinder OR (issues.confidential = TRUE AND (issues.author_id = :user_id OR EXISTS (SELECT TRUE FROM issue_assignees WHERE user_id = :user_id AND issue_id = issues.id) + OR issues.assignee_id = :user_id OR issues.project_id IN(:project_ids)))', user_id: user.id, project_ids: user.authorized_projects(Gitlab::Access::REPORTER).select(:id)) diff --git a/app/models/concerns/assignee_live_migration.rb b/app/models/concerns/assignee_live_migration.rb new file mode 100644 index 00000000000..bf0fbc7a9d1 --- /dev/null +++ b/app/models/concerns/assignee_live_migration.rb @@ -0,0 +1,20 @@ +module AssigneeLiveMigration + # This method is a part of live migration concept. We need to migrate assignee_id + # to a separate table issue_assignees + def migrate_assignee + if assignee_needs_to_be_migrated? + Issue.transaction do + IssueAssignee.create(issue_id: id, user_id: assignee_id) + update(assignee_id: nil) + end + + return true + end + + false + end + + def assignee_needs_to_be_migrated? + assignee_id + end +end diff --git a/app/models/issue.rb b/app/models/issue.rb index ecfc33ec1a1..89e269f7872 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -9,6 +9,7 @@ class Issue < ActiveRecord::Base include Spammable include FasterCacheKeys include RelativePositioning + include AssigneeLiveMigration DueDateStruct = Struct.new(:title, :name).freeze NoDueDate = DueDateStruct.new('No Due Date', '0').freeze @@ -31,9 +32,9 @@ class Issue < ActiveRecord::Base scope :in_projects, ->(project_ids) { where(project_id: project_ids) } - scope :assigned, -> { where('EXISTS (SELECT TRUE FROM issue_assignees WHERE issue_id = issues.id)') } - scope :unassigned, -> { where('NOT EXISTS (SELECT TRUE FROM issue_assignees WHERE issue_id = issues.id)') } - scope :assigned_to, ->(u) { where('EXISTS (SELECT TRUE FROM issue_assignees WHERE user_id = ? AND issue_id = issues.id)', u.id)} + scope :assigned, -> { where('EXISTS (SELECT TRUE FROM issue_assignees WHERE issue_id = issues.id) OR issues.assignee_id IS NOT NULL') } + scope :unassigned, -> { where('NOT EXISTS (SELECT TRUE FROM issue_assignees WHERE issue_id = issues.id) OR issues.assignee_id IS NULL') } + scope :assigned_to, ->(u) { where('EXISTS (SELECT TRUE FROM issue_assignees WHERE user_id = :user_id AND issue_id = issues.id) OR issues.assignee_id = :user_id', user_id: u.id)} scope :without_due_date, -> { where(due_date: nil) } scope :due_before, ->(date) { where('issues.due_date < ?', date) } diff --git a/app/services/issues/update_service.rb b/app/services/issues/update_service.rb index cd9f9a4a16e..1d558f5dd12 100644 --- a/app/services/issues/update_service.rb +++ b/app/services/issues/update_service.rb @@ -3,6 +3,7 @@ module Issues include SpamCheckService def execute(issue) + issue.migrate_assignee handle_move_between_iids(issue) filter_spam_check_params update(issue) |