Class: MongoClarify::Investigate

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo_clarify/investigate.rb

Instance Method Summary collapse

Constructor Details

#initialize(explain) ⇒ Investigate

Returns a new instance of Investigate.



9
10
11
# File 'lib/mongo_clarify/investigate.rb', line 9

def initialize(explain)
  @explain = explain
end

Instance Method Details

#execution_statsObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mongo_clarify/investigate.rb', line 26

def execution_stats
  match(@explain) do
    with(Hash.(executionStats: Hash.(nReturned: n, executionTimeMillis: msec, totalKeysExamined: keys, totalDocsExamined: docs))) do
      {
        n_returned: n,
        execution_time_millis: msec,
        total_keys_examined: keys,
        total_docs_examined: docs
      }
    end
  end
rescue PatternMatch::NoMatchingPatternError
  nil
end

#operation_methodObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mongo_clarify/investigate.rb', line 13

def operation_method
  match(@explain) do
    with(Hash.(queryPlanner: Hash.(winningPlan: Hash.(stage: 'COLLSCAN')))) do
      'Collection Scan'
    end
    with(Hash.(queryPlanner: Hash.(winningPlan: Hash.(stage: 'FETCH', inputStage: Hash.(stage: 'IXSCAN', indexName: index_name))))) do
      "Index Scan (Index Name: #{index_name})"
    end
  end
rescue PatternMatch::NoMatchingPatternError
  nil
end