diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2018-01-11 15:39:23 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2018-01-11 15:39:23 +0300 |
commit | 0a51eae58642d2c1df27166092efa2d75ec1cbe0 (patch) | |
tree | d76583f425e49e1c1417cafdecf96059e949b93a /app/models | |
parent | ec94d906b7cb3e5854834e823318a32e161e30a0 (diff) | |
parent | e6a1db6d9e3036ae0c9dc677f9029f5acf37f9f6 (diff) |
Merge branch '38068-commits-count' into 'master'
Resolve "Store the number of merge request commits in merge_request_diffs.commits_count"
Closes #38068
See merge request gitlab-org/gitlab-ce!16164
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/merge_request_diff.rb | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index e35de9b97ee..afab72930c1 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -49,6 +49,7 @@ class MergeRequestDiff < ActiveRecord::Base ensure_commit_shas save_commits save_diffs + save keep_around_commits end @@ -56,7 +57,6 @@ class MergeRequestDiff < ActiveRecord::Base self.start_commit_sha ||= merge_request.target_branch_sha self.head_commit_sha ||= merge_request.source_branch_sha self.base_commit_sha ||= find_base_sha - save end # Override head_commit_sha to keep compatibility with merge request diff @@ -195,7 +195,7 @@ class MergeRequestDiff < ActiveRecord::Base end def commits_count - merge_request_diff_commits.size + super || merge_request_diff_commits.size end private @@ -264,13 +264,16 @@ class MergeRequestDiff < ActiveRecord::Base new_attributes[:state] = :overflow if diff_collection.overflow? end - update(new_attributes) + assign_attributes(new_attributes) end def save_commits MergeRequestDiffCommit.create_bulk(self.id, compare.commits.reverse) - merge_request_diff_commits.reload + # merge_request_diff_commits.reload is preferred way to reload associated + # objects but it returns cached result for some reason in this case + commits = merge_request_diff_commits(true) + self.commits_count = commits.size end def repository |