active_record_query_stats 0.1.0 → 0.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 755c5bc78883b1118c0e46605155798671d8e0800303e2eb642021c16ce16c6e
|
4
|
+
data.tar.gz: 18de36375198cc350c92a8b04a3fd2ef9cc8d4433e89493c9a039d4c2f382746
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9848092049fa3b9fd2d34f6035a63e2cc772ba6ae18828cbc9b19a20b3f47a377ddfeb6a02a5d6caa7abfa87f610a6fc973c01927986077b0f13b043a3a6b91
|
7
|
+
data.tar.gz: b733b023fc6853c2f1d3bff32d25c0cea6c4fc7d25203fed5b15a0ace53e09b627b54d8ddabf103cd0c5baf792c2430595e72478169391be7c0a32c3bae31745
|
data/README.md
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/active_record_query_stats.svg)](https://badge.fury.io/rb/active_record_query_stats)
|
4
4
|
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
|
5
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/
|
6
|
-
[![Test Coverage](https://api.codeclimate.com/v1/badges/
|
5
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/9bcbeb90bc7f141fc211/maintainability)](https://codeclimate.com/github/tian-im/active_record_query_stats/maintainability)
|
6
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/9bcbeb90bc7f141fc211/test_coverage)](https://codeclimate.com/github/tian-im/active_record_query_stats/test_coverage)
|
7
7
|
|
8
8
|
ActiveRecordQueryStats produces simple ActiveRecord query stats at the end of each request in the following format:
|
9
9
|
|
@@ -12,7 +12,7 @@ Query Stats
|
|
12
12
|
-----------
|
13
13
|
total: 6, real: 5, cached: 1
|
14
14
|
select: 4, insert: 0, update: 1, delete: 0
|
15
|
-
transaction: 0, savepoint: 0,
|
15
|
+
transaction: 0, savepoint: 0, rollback: 0, lock: 0, other: 0
|
16
16
|
```
|
17
17
|
|
18
18
|
- **total:** total queries occurred during the request.
|
@@ -58,7 +58,7 @@ en:
|
|
58
58
|
-----------
|
59
59
|
total: %{total}, real: %{real}, cached: %{cached}
|
60
60
|
select: %{select}, insert: %{insert}, update: %{update}, delete: %{delete}
|
61
|
-
transaction: %{transaction}, savepoint: %{savepoint},
|
61
|
+
transaction: %{transaction}, savepoint: %{savepoint}, rollback: %{rollback}, lock: %{lock}, other: %{other}
|
62
62
|
```
|
63
63
|
|
64
64
|
## Implementation
|
@@ -24,20 +24,19 @@ module ActiveRecordQueryStats
|
|
24
24
|
delegate(*Summary.instance_methods(false), to: :summary)
|
25
25
|
|
26
26
|
def increase_transaction_related
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
when /transaction\s*\Z/i then increase_transaction
|
31
|
-
when /\A\s*(release )?savepoint/i then increase_savepoint
|
27
|
+
if rollback_query? then increase_rollback && increase_transaction
|
28
|
+
elsif savepoint_query? then increase_savepoint && increase_transaction
|
29
|
+
elsif transaction_query? then increase_transaction
|
32
30
|
end
|
33
31
|
end
|
34
32
|
|
35
33
|
def increase_statements
|
36
34
|
case payload[:sql]
|
37
|
-
when /\A\s*
|
38
|
-
when /\A\s*
|
39
|
-
when /\A\s*
|
40
|
-
when /\A\s*
|
35
|
+
when /\s*SELECT .*FOR UPDATE\b/mi, /\A\s*LOCK\b/mi then increase_lock
|
36
|
+
when /\A\s*SELECT/i then increase_select
|
37
|
+
when /\A\s*INSERT/i then increase_insert
|
38
|
+
when /\A\s*UPDATE/i then increase_update
|
39
|
+
when /\A\s*DELETE/i then increase_delete
|
41
40
|
end
|
42
41
|
end
|
43
42
|
|
@@ -64,5 +63,17 @@ module ActiveRecordQueryStats
|
|
64
63
|
def cached_query?
|
65
64
|
/CACHE/i =~ payload[:name] || payload[:cached]
|
66
65
|
end
|
66
|
+
|
67
|
+
def rollback_query?
|
68
|
+
/\A\s*ROLLBACK/mi =~ payload[:sql]
|
69
|
+
end
|
70
|
+
|
71
|
+
def savepoint_query?
|
72
|
+
/\A\s*(RELEASE )?SAVEPOINT/mi =~ payload[:sql]
|
73
|
+
end
|
74
|
+
|
75
|
+
def transaction_query?
|
76
|
+
/TRANSACTION\s*\Z/i =~ payload[:sql] || /TRANSACTION/i =~ payload[:name]
|
77
|
+
end
|
67
78
|
end
|
68
79
|
end
|
@@ -12,9 +12,15 @@ module ActiveRecordQueryStats
|
|
12
12
|
RequestStore[:active_record_query_stats] ||= new
|
13
13
|
end
|
14
14
|
|
15
|
+
def initialize
|
16
|
+
STATS.each do |field|
|
17
|
+
instance_variable_set :"@#{field}", 0
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
15
21
|
STATS.each do |field|
|
16
22
|
define_method field do
|
17
|
-
instance_variable_get(:"@#{field}")
|
23
|
+
instance_variable_get(:"@#{field}")
|
18
24
|
end
|
19
25
|
|
20
26
|
define_method :"increase_#{field}" do
|
@@ -5,4 +5,4 @@ en:
|
|
5
5
|
-----------
|
6
6
|
total: %{total}, real: %{real}, cached: %{cached}
|
7
7
|
select: %{select}, insert: %{insert}, update: %{update}, delete: %{delete}
|
8
|
-
transaction: %{transaction}, savepoint: %{savepoint},
|
8
|
+
transaction: %{transaction}, savepoint: %{savepoint}, rollback: %{rollback}, lock: %{lock}, other: %{other}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_query_stats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tian Chen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|