diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-08-03 15:13:39 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-08-03 15:13:39 +0900 |
commit | 85af3ea21a5a772cb22756190268ba3f921a6400 (patch) | |
tree | 4231bb48df2693c9600b5c5b7dabb9bae41c1d3e /app/models/merge_request.rb | |
parent | 1f53cf7cf0cb53b5d69ab141fa9020356e62027e (diff) | |
download | gitlab-ce-85af3ea21a5a772cb22756190268ba3f921a6400.tar.gz |
Added unique identifier to calculate_reactive_cache. Decoupled comparison logic to service. Fixed N+1 select queries.
Diffstat (limited to 'app/models/merge_request.rb')
-rw-r--r-- | app/models/merge_request.rb | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 9f8ebd9b4ca..6de44751f1b 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -1022,29 +1022,22 @@ class MergeRequest < ActiveRecord::Base end def compare_test_reports - unless actual_head_pipeline && actual_head_pipeline.has_test_reports? - return { status: :error, status_reason: 'head pipeline does not have test reports' } + unless has_test_reports? + return { status: :error, status_reason: 'This merge request does not have test reports' } end - with_reactive_cache(base_pipeline&.iid, actual_head_pipeline.iid) { |data| data } || { status: :parsing } + with_reactive_cache( + :compare_test_results, + base_pipeline&.iid, + actual_head_pipeline.iid) { |data| data } || { status: :parsing } end - def calculate_reactive_cache(base_pipeline_iid, head_pipeline_iid) - begin - base_pipeline = project.pipelines.find_by_iid(base_pipeline_iid) - head_pipeline = project.pipelines.find_by_iid(head_pipeline_iid) - - comparer = Gitlab::Ci::Reports::TestReportsComparer - .new(base_pipeline&.test_reports, head_pipeline.test_reports) - - { - status: :parsed, - data: TestReportsComparerSerializer - .new(project: project) - .represent(comparer).to_json - } - rescue => e - { status: :error, status_reason: e.message } + def calculate_reactive_cache(identifier, *args) + case identifier.to_sym + when :compare_test_results + Ci::CompareTestReportsService.new(project).execute(*args) + else + raise NotImplementedError, "Unknown identifier: #{identifier}" end end |