diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2017-04-06 16:20:27 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-04-06 16:20:27 +0000 |
commit | 828d81ee1f6aaaf6ab9de1ed0c675ff961831c17 (patch) | |
tree | a8e9ba81f60e1185a86920ace8b9b2e9352e8ce9 /app/controllers | |
parent | 514dc1a0848616b93e8910c6c48eea4f64391884 (diff) | |
download | gitlab-ce-828d81ee1f6aaaf6ab9de1ed0c675ff961831c17.tar.gz |
Optimise trace handling code to use streaming instead of full read
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/projects/builds_controller.rb | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/app/controllers/projects/builds_controller.rb b/app/controllers/projects/builds_controller.rb index 3f3c90a49ab..add66ce9f84 100644 --- a/app/controllers/projects/builds_controller.rb +++ b/app/controllers/projects/builds_controller.rb @@ -31,25 +31,25 @@ class Projects::BuildsController < Projects::ApplicationController @builds = @project.pipelines.find_by_sha(@build.sha).builds.order('id DESC') @builds = @builds.where("id not in (?)", @build.id) @pipeline = @build.pipeline - - respond_to do |format| - format.html - format.json do - render json: { - id: @build.id, - status: @build.status, - trace_html: @build.trace_html - } - end - end end def trace - respond_to do |format| - format.json do - state = params[:state].presence - render json: @build.trace_with_state(state: state). - merge!(id: @build.id, status: @build.status) + build.trace.read do |stream| + respond_to do |format| + format.json do + result = { + id: @build.id, status: @build.status, complete: @build.complete? + } + + if stream.valid? + stream.limit + state = params[:state].presence + trace = stream.html_with_state(state) + result.merge!(trace.to_h) + end + + render json: result + end end end end @@ -86,10 +86,12 @@ class Projects::BuildsController < Projects::ApplicationController end def raw - if @build.has_trace_file? - send_file @build.trace_file_path, type: 'text/plain; charset=utf-8', disposition: 'inline' - else - render_404 + build.trace.read do |stream| + if stream.file? + send_file stream.path, type: 'text/plain; charset=utf-8', disposition: 'inline' + else + render_404 + end end end |