diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-04-06 14:31:29 +0200 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-04-06 14:32:40 +0200 |
commit | 3015e768f53806abf788b106d8be84486f30cd10 (patch) | |
tree | 4c4cfa59ff2aecd2e7e3dd41d34126558c6f9e9c | |
parent | 062806e47da00dde37a2a62d7a5c6ede8341582c (diff) | |
download | gitlab-ce-3015e768f53806abf788b106d8be84486f30cd10.tar.gz |
Revert "Reverse pipelines controller changes"
This reverts commit 0a60cdb110754a5e894ca1a2aa619842f2d98d1a.
-rw-r--r-- | app/controllers/projects/pipelines_controller.rb | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/app/controllers/projects/pipelines_controller.rb b/app/controllers/projects/pipelines_controller.rb index 43a1abaa662..f8aba16203e 100644 --- a/app/controllers/projects/pipelines_controller.rb +++ b/app/controllers/projects/pipelines_controller.rb @@ -1,3 +1,35 @@ +module ActiveRecord + class QueryRecorder + attr_reader :log + attr_reader :start + attr_reader :end + + def initialize(&block) + @log = [] + @start = Time.now + ActiveSupport::Notifications.subscribed(method(:callback), 'sql.active_record', &block) + @end = Time.now + end + + def callback(name, start, finish, message_id, values) + return if %w(SCHEMA).include?(values[:name]) + @log << values[:sql] + end + + def time + @end - @start + end + + def count + @log.count + end + + def log_message + @log.join("\n\n") + end + end +end + class Projects::PipelinesController < Projects::ApplicationController before_action :pipeline, except: [:index, :new, :create, :charts] before_action :commit, only: [:show, :builds] @@ -29,18 +61,15 @@ class Projects::PipelinesController < Projects::ApplicationController respond_to do |format| format.html format.json do - render json: { - pipelines: PipelineSerializer + result = nil + queries = ActiveRecord::QueryRecorder.new do + result = PipelineSerializer .new(project: @project, user: @current_user) .with_pagination(request, response) - .represent(@pipelines), - count: { - all: @pipelines_count, - running: @running_count, - pending: @pending_count, - finished: @finished_count, - } - } + .represent(@pipelines) + end + + render json: { aa_queries: queries.count, aa_time: queries.time, result: result } end end end |