ar-query-matchers 0.5.2.pre.6 → 0.5.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab18e9a530a6577ba47fbc78341913bc83ec6c2976dfd3404be8819d346fcab8
|
4
|
+
data.tar.gz: 9801846663ecc57468f79a66a7c12f170f9ddb2fef79d35aa33c36910c8d9a8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa331847dc1130257f6af7cc567e636ccedc8c7cecbd90383606f4c17050ab7c05546b51aa3cea040f1416082e45d98c04182341a13fddcfbbb66148183b9c43
|
7
|
+
data.tar.gz: 4becc7972b419b4e55d0f5cf55292ec8dfad6d6a1804bf9315c4368e842ec8a6c98506028b1ae7df41d2736f8a80b67fb745f1c9bb9e98328092db745baf8619
|
data/CHANGELOG.md
CHANGED
@@ -6,9 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
-
## [0.5.2] - 2021-05-
|
9
|
+
## [0.5.2] - 2021-05-26
|
10
10
|
### Changed
|
11
|
-
-
|
11
|
+
- Update MODEL_SQL_PATTERN to allow for more granular matches; remove MODEL_LOAD_PATTERN
|
12
12
|
|
13
13
|
## [0.5.1] - 2020-11-19
|
14
14
|
### Changed
|
@@ -23,7 +23,7 @@ module ArQueryMatchers
|
|
23
23
|
# for inserts, name is always 'SQL', we have to rely on pattern matching the query string.
|
24
24
|
select_from_table = sql.match(TABLE_NAME_SQL_PATTERN)
|
25
25
|
|
26
|
-
|
26
|
+
TableName.new(select_from_table[:table_name]) if select_from_table
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -15,15 +15,24 @@ module ArQueryMatchers
|
|
15
15
|
end
|
16
16
|
|
17
17
|
class LoadQueryFilter < Queries::QueryFilter
|
18
|
+
# Matches named SQL operations like the following:
|
19
|
+
# 'User Load'
|
20
|
+
MODEL_LOAD_PATTERN = /\A(?<model_name>[\w:]+) (Load|Exists)\Z/.freeze
|
21
|
+
|
18
22
|
# Matches unnamed SQL operations like the following:
|
19
|
-
# "SELECT * FROM `users` ..."
|
23
|
+
# "SELECT COUNT(*) FROM `users` ..."
|
20
24
|
MODEL_SQL_PATTERN = /SELECT (?:(?!SELECT).)* FROM [`"](?<table_name>[^`"]+)[`"]/.freeze
|
21
25
|
|
22
|
-
def filter_map(
|
23
|
-
#
|
26
|
+
def filter_map(name, sql)
|
27
|
+
# First check for a `SELECT * FROM` query that ActiveRecord has
|
28
|
+
# helpfully named for us in the payload
|
29
|
+
match = name.match(MODEL_LOAD_PATTERN)
|
30
|
+
return ModelName.new(match[:model_name]) if match
|
31
|
+
|
32
|
+
# Fall back to pattern-matching on the table name in a COUNT and looking
|
24
33
|
# up the table name from ActiveRecord's loaded descendants.
|
25
|
-
|
26
|
-
|
34
|
+
select_from_table = sql.match(MODEL_SQL_PATTERN)
|
35
|
+
TableName.new(select_from_table[:table_name]) if select_from_table
|
27
36
|
end
|
28
37
|
end
|
29
38
|
end
|
@@ -81,13 +81,9 @@ module ArQueryMatchers
|
|
81
81
|
# Given a `sql.active_record` event, figure out which model is being
|
82
82
|
# accessed. Some of the simpler queries have a :name key that makes this
|
83
83
|
# really easy. Others require parsing the SQL by hand.
|
84
|
-
|
85
|
-
|
86
|
-
# Round to microseconds
|
87
|
-
results&.each do |result|
|
88
|
-
model_name = result.model_name
|
89
|
-
next unless model_name
|
84
|
+
model_name = @query_filter.filter_map(payload[:name] || '', payload[:sql] || '')&.model_name
|
90
85
|
|
86
|
+
if model_name
|
91
87
|
comment = payload[:sql].match(MARGINALIA_SQL_COMMENT_PATTERN)
|
92
88
|
queries[model_name][:lines] << comment[:line] if comment
|
93
89
|
queries[model_name][:count] += 1
|
@@ -22,7 +22,7 @@ module ArQueryMatchers
|
|
22
22
|
def filter_map(_name, sql)
|
23
23
|
# for updates, name is always 'SQL', we have to rely on pattern matching on the query string instead.
|
24
24
|
select_from_table = sql.match(TABLE_NAME_SQL_PATTERN)
|
25
|
-
|
25
|
+
TableName.new(select_from_table[:table_name]) if select_from_table
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar-query-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.2
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matan Zruya
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -186,9 +186,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
186
186
|
version: '0'
|
187
187
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
188
188
|
requirements:
|
189
|
-
- - "
|
189
|
+
- - ">="
|
190
190
|
- !ruby/object:Gem::Version
|
191
|
-
version:
|
191
|
+
version: '0'
|
192
192
|
requirements: []
|
193
193
|
rubygems_version: 3.0.3.1
|
194
194
|
signing_key:
|