activerecord-analyze 0.10.2 → 0.11.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/.circleci/config.yml +1 -1
- data/lib/activerecord-analyze/main.rb +11 -0
- data/lib/activerecord-analyze/version.rb +1 -1
- data/lib/activerecord-analyze.rb +12 -0
- data/spec/analyze_sql_spec.rb +19 -0
- data/spec/main_spec.rb +16 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2887f876750f69c014a2327d188ddadfd127fa1da9eedad4402a8f6e1c3b821
|
4
|
+
data.tar.gz: 43244e2075b937b53fe880032f538f645b9fc3b70c14e72ffbe4027edbcf4f37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afe058da3dc7d385b78b48de4e81579bfeb3df79baa1c5c6c0ad9865fc54211605a77672144f33a48870c93830f211dd9d75c28695cb8812b0921594137005b5
|
7
|
+
data.tar.gz: 19d38c62f0f0e209dc15c4760537be105068138eba5aa41dbd6496fa67218c6e54c5f5df08e0bbe3ba67bffdc2b146822320bf2be801bb4b60b60300a529ee99
|
data/.circleci/config.yml
CHANGED
@@ -5,7 +5,7 @@ jobs:
|
|
5
5
|
- image: circleci/ruby:2.6.5
|
6
6
|
environment:
|
7
7
|
DATABASE_URL: postgresql://postgres:secret@localhost:5432/activerecord-analyze-test
|
8
|
-
- image:
|
8
|
+
- image: cimg/postgres:12.10
|
9
9
|
environment:
|
10
10
|
POSTGRES_USER: postgres
|
11
11
|
POSTGRES_DB: activerecord-analyze-test
|
@@ -16,6 +16,17 @@ end
|
|
16
16
|
module ActiveRecord
|
17
17
|
class Relation
|
18
18
|
def analyze(opts = {})
|
19
|
+
if opts[:full_debug] == true
|
20
|
+
opts = {
|
21
|
+
format: :pretty_json,
|
22
|
+
verbose: true,
|
23
|
+
costs: true,
|
24
|
+
buffers: true,
|
25
|
+
timing: true,
|
26
|
+
summary: true
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
19
30
|
res = exec_analyze(collecting_queries_for_explain { exec_queries }, opts)
|
20
31
|
if [:json, :hash, :pretty_json].include?(opts[:format])
|
21
32
|
start = res.index("[\n")
|
data/lib/activerecord-analyze.rb
CHANGED
@@ -4,6 +4,17 @@ require 'activerecord-analyze/main'
|
|
4
4
|
|
5
5
|
module ActiveRecordAnalyze
|
6
6
|
def self.analyze_sql(raw_sql, opts = {})
|
7
|
+
if opts[:full_debug] == true
|
8
|
+
opts = {
|
9
|
+
format: :pretty_json,
|
10
|
+
verbose: true,
|
11
|
+
costs: true,
|
12
|
+
buffers: true,
|
13
|
+
timing: true,
|
14
|
+
summary: true
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
7
18
|
prefix = "EXPLAIN #{build_prefix(opts)}"
|
8
19
|
|
9
20
|
result = ActiveRecord::Base.connection.execute("#{prefix} #{raw_sql}").to_a
|
@@ -80,5 +91,6 @@ module ActiveRecordAnalyze
|
|
80
91
|
.gsub(/\(\s?\s?\s?,/, "(")
|
81
92
|
.gsub(/\s,\s/, " ")
|
82
93
|
.gsub(/\(\s?\)/, "")
|
94
|
+
.gsub(/,\s+\)/, ")")
|
83
95
|
end
|
84
96
|
end
|
data/spec/analyze_sql_spec.rb
CHANGED
@@ -80,4 +80,23 @@ describe "ActiveRecord analyze" do
|
|
80
80
|
]
|
81
81
|
end
|
82
82
|
end
|
83
|
+
|
84
|
+
describe "supports full_debug option" do
|
85
|
+
let(:raw_sql) do
|
86
|
+
"SELECT \"users\".* FROM \"users\" WHERE \"users\".\"email\" IS NOT NULL LIMIT 10"
|
87
|
+
end
|
88
|
+
|
89
|
+
let(:opts) do
|
90
|
+
{
|
91
|
+
full_debug: true
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
it "works" do
|
96
|
+
puts result
|
97
|
+
expect(JSON.parse(result)[0].keys.sort).to eq [
|
98
|
+
"Execution Time", "Plan", "Planning Time", "Triggers"
|
99
|
+
]
|
100
|
+
end
|
101
|
+
end
|
83
102
|
end
|
data/spec/main_spec.rb
CHANGED
@@ -50,6 +50,22 @@ describe "ActiveRecord analyze" do
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
+
describe "analyze:false with some format option" do
|
54
|
+
it "works" do
|
55
|
+
result = User.all.analyze(format: :pretty_json, analyze: false)
|
56
|
+
expect(JSON.parse(result)[0].keys.sort).to eq ["Plan"]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "full_debug" do
|
61
|
+
it "works" do
|
62
|
+
result = User.all.analyze(full_debug: true)
|
63
|
+
expect(JSON.parse(result)[0].keys.sort).to eq [
|
64
|
+
"Execution Time", "Plan", "Planning Time", "Triggers"
|
65
|
+
]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
53
69
|
describe "supports options" do
|
54
70
|
it "works" do
|
55
71
|
result = User.all.limit(10).where.not(email: nil).analyze(
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-analyze
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pawurb
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -108,7 +108,7 @@ homepage: http://github.com/pawurb/activerecord-analyze
|
|
108
108
|
licenses:
|
109
109
|
- MIT
|
110
110
|
metadata: {}
|
111
|
-
post_install_message:
|
111
|
+
post_install_message:
|
112
112
|
rdoc_options: []
|
113
113
|
require_paths:
|
114
114
|
- lib
|
@@ -123,8 +123,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
requirements: []
|
126
|
-
rubygems_version: 3.
|
127
|
-
signing_key:
|
126
|
+
rubygems_version: 3.3.7
|
127
|
+
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: Add EXPLAIN ANALYZE to Active Record query objects
|
130
130
|
test_files:
|