summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-07-25 16:25:05 +0900
committerShinya Maeda <shinya@gitlab.com>2018-07-25 16:25:05 +0900
commit8f3b9c0d313f9eeef1b6e6b5eccf622156e960bd (patch)
tree67ec4a9c056a669a077e89de812ecbc3e16f1249
parent9cabd787fc392c7a442cd8b2de798da36c8b67bc (diff)
downloadgitlab-ce-8f3b9c0d313f9eeef1b6e6b5eccf622156e960bd.tar.gz
Skip comparison if head and base pipelines are the same as before
-rw-r--r--app/controllers/projects/merge_requests_controller.rb6
-rw-r--r--app/models/merge_request.rb22
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