active_record_query_counter 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGE_LOG.md +6 -2
- data/VERSION +1 -1
- data/lib/active_record_query_counter.rb +32 -5
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 519c3f12525967d15b3c72c1d81f461812e4716420ab58f5360d6cc5f9876796
|
|
4
|
+
data.tar.gz: 849e4d66eba96b9cf05268f0373315bc72f9285f14abb544f0cfe91ae1ecd3de
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 41087b8c0ea5b7f0775f15477578f09f7ccfe26f3f6135ecbcd521f273401b7dc43d1657febffd4a79bda61ade46247302eb0c9df192f5be51abb0627c76b55f
|
|
7
|
+
data.tar.gz: ced16b82fba34bc1a25c7912584ac12e56dc17a584d44c2f8faad1ea80cdd292dc2f1517fc14c32f03f13652309c69d4fbb9ea8bbad08c5bb386306ec6b1736e
|
data/CHANGE_LOG.md
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.1.
|
|
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
|
|
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
|
-
@
|
|
20
|
-
|
|
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
|
-
|
|
50
|
-
|
|
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.
|
|
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-
|
|
11
|
+
date: 2020-11-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|