diff options
-rw-r--r-- | app/controllers/projects/merge_requests_controller.rb | 6 | ||||
-rw-r--r-- | app/models/merge_request.rb | 22 |
2 files changed, 22 insertions, 6 deletions
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index 5f7f6c66376..2f15cf341b0 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -103,10 +103,10 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo result = @merge_request.compare_test_reports case result[:status] - when :parsing + when :waiting render json: '', status: :no_content - when :success - render json: JSON.parse(result[:data]), status: :ok + when :parsed + render json: result[:data], status: :ok when :error render json: { status_reason: result[:status_reason] }, status: :internal_server_error else diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index f8434a0873a..9fbd1c023e3 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -13,6 +13,7 @@ class MergeRequest < ActiveRecord::Base include ReactiveCaching self.reactive_cache_key = ->(model) { [model.project.id, model.iid] } # For parsing test reports + self.reactive_cache_refresh_interval = 10.seconds # TODO: What is the best interval which doesn't make users feel GitLab is slow? ignore_column :locked_at, :ref_fetched, @@ -1017,18 +1018,33 @@ class MergeRequest < ActiveRecord::Base end def compare_test_reports - with_reactive_cache { |data| return data } || { status: :parsing } + with_reactive_cache { |data| data } || { status: :waiting } end + ## + # TODO: FE should restart polling if user retried head pipeline. + # TODO: How do we deal with the following events? + # 1. User retried a head pipeline + # 1. User retried a base pipeline + # + # To hook the event of base pipeline's retry would be tricky because front-end doesn't hook the evenet today. def calculate_reactive_cache - return { status: :error, status_reason: 'Missing head pipeline' } unless actual_head_pipeline + return { status: :waiting } unless actual_head_pipeline + return { status: :waiting } unless actual_head_pipeline.has_test_reports? + + # If base and head pipelines have not been updated, skip the comparison + data = Rails.cache.read(full_reactive_cache_key) + return data if actual_head_pipeline&.updated_at == data&.dig(:head_pipeline_updated_at) && + base_pipeline&.updated_at == data&.dig(:base_pipeline_updated_at) begin comparer = Gitlab::Ci::Reports::TestReportsComparer .new(base_pipeline&.test_reports, actual_head_pipeline&.test_reports) { - status: :success, + status: :parsed, + head_pipeline_updated_at: actual_head_pipeline.updated_at, + base_pipeline_updated_at: base_pipeline&.updated_at, data: TestReportsComparerSerializer .new(project: project, current_user: nil) .represent(comparer).to_json |