summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2018-08-06 15:44:40 +0000
committerSean McGivern <sean@mcgivern.me.uk>2018-08-06 15:44:40 +0000
commitb4415c01740430cef58baf9bb0cbda2fb1055edb (patch)
tree89ddade2adcb40d95b710760d4fc806c52f94ada /app/models
parent415b2f943ba80ef3b6746af0a98c6dbe062e803c (diff)
parentfdb5f285f924e653400f7bbe18d13718c469d74f (diff)
downloadgitlab-ce-b4415c01740430cef58baf9bb0cbda2fb1055edb.tar.gz
Merge branch 'issue_44821' into 'master'
Retrieve merge request closing issues from database cache Closes #44821 See merge request gitlab-org/gitlab-ce!20911
Diffstat (limited to 'app/models')
-rw-r--r--app/models/merge_request.rb21
1 files changed, 18 insertions, 3 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 6de44751f1b..acad8b91e9f 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -60,6 +60,8 @@ class MergeRequest < ActiveRecord::Base
class_name: 'MergeRequestsClosingIssues',
dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent
+ has_many :cached_closes_issues, through: :merge_requests_closing_issues, source: :issue
+
belongs_to :assignee, class_name: "User"
serialize :merge_params, Hash # rubocop:disable Cop/ActiveRecordSerialize
@@ -763,8 +765,9 @@ class MergeRequest < ActiveRecord::Base
# Calculating this information for a number of merge requests requires
# running `ReferenceExtractor` on each of them separately.
# This optimization does not apply to issues from external sources.
- def cache_merge_request_closes_issues!(current_user)
+ def cache_merge_request_closes_issues!(current_user = self.author)
return unless project.issues_enabled?
+ return if closed? || merged?
transaction do
self.merge_requests_closing_issues.delete_all
@@ -777,6 +780,18 @@ class MergeRequest < ActiveRecord::Base
end
end
+ def visible_closing_issues_for(current_user = self.author)
+ strong_memoize(:visible_closing_issues_for) do
+ if self.target_project.has_external_issue_tracker?
+ closes_issues(current_user)
+ else
+ cached_closes_issues.select do |issue|
+ Ability.allowed?(current_user, :read_issue, issue)
+ end
+ end
+ end
+ end
+
# Return the set of issues that will be closed if this merge request is accepted.
def closes_issues(current_user = self.author)
if target_branch == project.default_branch
@@ -796,7 +811,7 @@ class MergeRequest < ActiveRecord::Base
ext = Gitlab::ReferenceExtractor.new(project, current_user)
ext.analyze("#{title}\n#{description}")
- ext.issues - closes_issues(current_user)
+ ext.issues - visible_closing_issues_for(current_user)
end
def target_project_path
@@ -844,7 +859,7 @@ class MergeRequest < ActiveRecord::Base
end
def merge_commit_message(include_description: false)
- closes_issues_references = closes_issues.map do |issue|
+ closes_issues_references = visible_closing_issues_for.map do |issue|
issue.to_reference(target_project)
end