summaryrefslogtreecommitdiff
path: root/lib/peek/views/rugged.rb
blob: 3ed54a010f8564f2d0274a2e9363c98dceea8906 (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
44
45
46
# 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_ms
      end

      def calls
        ::Gitlab::RuggedInstrumentation.query_count
      end

      def call_details
        ::Gitlab::RuggedInstrumentation.list_call_details
      end

      def format_call_details(call)
        super.merge(args: format_args(call[:args]))
      end

      def format_args(args)
        args.map do |arg|
          # ActiveSupport::JSON recursively calls as_json on all
          # instance variables, and if that instance variable points to
          # something that refers back to the same instance, we can wind
          # up in an infinite loop. Currently this only seems to happen with
          # Gitlab::Git::Repository and ::Repository.
          if arg.instance_variables.present?
            arg.to_s
          else
            arg
          end
        end
      end
    end
  end
end