summaryrefslogtreecommitdiff
path: root/lib/peek/views/rugged.rb
blob: f0cd520fb8b0c463774511f23dedeac9cd6c8432 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true

module Peek
  module Views
    class Rugged < DetailedView
      def results
        return {} unless calls > 0

        super
      end

      private

      def duration
        ::Gitlab::RuggedInstrumentation.query_time
      end

      def calls
        ::Gitlab::RuggedInstrumentation.query_count
      end

      def call_details
        ::Gitlab::RuggedInstrumentation.list_call_details
      end

      def format_call_details(call)
        call.merge(duration: (call[:duration] * 1000).round(3),
                   args: format_args(call[:args]))
      end

      def format_args(args)
        args.map do |arg|
          # Needed to avoid infinite as_json calls
          if arg.is_a?(Gitlab::Git::Repository)
            arg.to_s
          else
            arg
          end
        end
      end
    end
  end
end