active_record_query_stats 0.1.0 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7616eb499befdd021733555a3d398dac7b92e97d10ff68428e99f8d82f313cee
4
- data.tar.gz: 9a2e50b46a3eb1fc891a73ed2389a5a78f6de22fbdaa63a5b3c792a6728e8f91
3
+ metadata.gz: 755c5bc78883b1118c0e46605155798671d8e0800303e2eb642021c16ce16c6e
4
+ data.tar.gz: 18de36375198cc350c92a8b04a3fd2ef9cc8d4433e89493c9a039d4c2f382746
5
5
  SHA512:
6
- metadata.gz: 5757368a32479b2d53f131df441524656142cc4e311b422a32f70c1a703e6983cb3107f76de17b046fc45615834996295b8b93d0424ff96ae4c1a6cc379ff4d8
7
- data.tar.gz: e857808cd7cc2d5834a0d96c16033a33e72de951908ab516ef68ace4d3ce18fd6eca6e455f4bfeba7ec0c2ec47c52a59929a836d46e2d6dc899cfc3650b802dc
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/9ba0a610043a2e1a9e74/maintainability)](https://codeclimate.com/github/tian-im/active_record_query_stats/maintainability)
6
- [![Test Coverage](https://api.codeclimate.com/v1/badges/9ba0a610043a2e1a9e74/test_coverage)](https://codeclimate.com/github/tian-im/active_record_query_stats/test_coverage)
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, lock: 0, rollback: 0, other: 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}, lock: %{lock}, rollback: %{rollback}, other: %{other}
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
- case payload[:sql]
28
- when /\A\s*rollback/mi then increase_rollback
29
- when /select .*for update/mi, /\A\s*lock/mi then increase_lock
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*select/i then increase_select
38
- when /\A\s*insert/i then increase_insert
39
- when /\A\s*update/i then increase_update
40
- when /\A\s*delete/i then increase_delete
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}") || 0
23
+ instance_variable_get(:"@#{field}")
18
24
  end
19
25
 
20
26
  define_method :"increase_#{field}" do
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordQueryStats
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
@@ -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}, lock: %{lock}, rollback: %{rollback}, other: %{other}
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.0
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-17 00:00:00.000000000 Z
11
+ date: 2022-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack