active_record_query_counter 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7600a3d02b1c366ac42c06a7d4e781a4b622d84bca14d26e46b4e8aa34a09b32
4
- data.tar.gz: f2922c6db0478569029f1d869b2544dcbd0b1535ca95b0188691c5da9cddb561
3
+ metadata.gz: 519c3f12525967d15b3c72c1d81f461812e4716420ab58f5360d6cc5f9876796
4
+ data.tar.gz: 849e4d66eba96b9cf05268f0373315bc72f9285f14abb544f0cfe91ae1ecd3de
5
5
  SHA512:
6
- metadata.gz: 15370172634b6ebbf4a1bcf783e5ff0f0132f01e2a013c1ef457dac95d80369718fad4acf8408ea5e51bf5ffbd6adf96303ad64c1c4e67b2c6817776183b99ab
7
- data.tar.gz: b48d6016e2fd9feb9bbb30705e92484dd1b0376658e9c55267a526c17199e19e7d4d104863b1910d2d6a05a009d75ef2332a6bf606090640b055a3b550e852eb
6
+ metadata.gz: 41087b8c0ea5b7f0775f15477578f09f7ccfe26f3f6135ecbcd521f273401b7dc43d1657febffd4a79bda61ade46247302eb0c9df192f5be51abb0627c76b55f
7
+ data.tar.gz: ced16b82fba34bc1a25c7912584ac12e56dc17a584d44c2f8faad1ea80cdd292dc2f1517fc14c32f03f13652309c69d4fbb9ea8bbad08c5bb386306ec6b1736e
@@ -1,7 +1,11 @@
1
+ # 1.1.1
2
+
3
+ * Expose stack traces for where transactions are being committed.
4
+
1
5
  # 1.1.0
2
6
 
3
- * Add transaction counts
7
+ * Add transaction counts.
4
8
 
5
9
  # 1.0.0
6
10
 
7
- * Initial release
11
+ * Initial release.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.1.1
@@ -11,13 +11,22 @@
11
11
  # end
12
12
  module ActiveRecordQueryCounter
13
13
  class Counter
14
- attr_accessor :query_count, :row_count, :query_time, :transaction_count, :transaction_time
14
+ attr_accessor :query_count, :row_count, :query_time
15
+ attr_reader :transactions
16
+
15
17
  def initialize
16
18
  @query_count = 0
17
19
  @row_count = 0
18
20
  @query_time = 0.0
19
- @transaction_count = 0
20
- @transaction_time = 0.0
21
+ @transactions = {}
22
+ end
23
+
24
+ def transaction_count
25
+ @transactions.size
26
+ end
27
+
28
+ def transaction_time
29
+ @transactions.values.sum { |count, time| time }
21
30
  end
22
31
  end
23
32
 
@@ -46,8 +55,21 @@ module ActiveRecordQueryCounter
46
55
  def increment_transaction(elapsed_time)
47
56
  counter = Thread.current[:database_query_counter]
48
57
  if counter.is_a?(Counter)
49
- counter.transaction_count += 1
50
- counter.transaction_time += elapsed_time
58
+ trace = caller
59
+ index = 0
60
+ caller.each do |line|
61
+ break unless line.start_with?(__FILE__)
62
+ index += 1
63
+ end
64
+ trace = trace[index, trace.length]
65
+ info = counter.transactions[trace]
66
+ if info
67
+ info[0] += 1
68
+ info[1] += elapsed_time
69
+ else
70
+ info = [1, elapsed_time]
71
+ counter.transactions[trace] = info
72
+ end
51
73
  end
52
74
  end
53
75
 
@@ -76,6 +98,11 @@ module ActiveRecordQueryCounter
76
98
  counter.transaction_time if counter.is_a?(Counter)
77
99
  end
78
100
 
101
+ def transactions
102
+ counter = Thread.current[:database_query_counter]
103
+ counter.transactions.dup if counter.is_a?(Counter)
104
+ end
105
+
79
106
  # Return the query info as a hash with keys :query_count, :row_count, :query_time
80
107
  # :transaction_count, and :transaction_type or nil if not inside a block where queries
81
108
  # are being counted.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_query_counter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-30 00:00:00.000000000 Z
11
+ date: 2020-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord