activerecord-analyze 0.10.2 → 0.11.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: 8871bdc597d0ba5c601a8b93b17aa037430297554ba074fa7ed448f7fce3f9d3
4
- data.tar.gz: 846ed95e10f289793e75c17bbae7ee0cd274a93c5af263777da59d66c1006acd
3
+ metadata.gz: a2887f876750f69c014a2327d188ddadfd127fa1da9eedad4402a8f6e1c3b821
4
+ data.tar.gz: 43244e2075b937b53fe880032f538f645b9fc3b70c14e72ffbe4027edbcf4f37
5
5
  SHA512:
6
- metadata.gz: 5699bbab0ed4d533d1c62ce5e02d1e54f5868db437cffee62a1be5fb5a34ad7c91fbb758d26ee6f227cb222e67e391564afbd53eb1a6cf1b197d1dfd3cf18b80
7
- data.tar.gz: b4d2a4ab6b79780d3f55584353381904a8a86c7cfe0f311646326b33f229c01097e250fd02f6569e69ecc8fe6ba89767aa39eac7f44b38f869e5a2e99479f3e0
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: circleci/postgres:11.5
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")
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordAnalyze
2
- VERSION = "0.10.2"
2
+ VERSION = "0.11.1"
3
3
  end
@@ -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
@@ -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.10.2
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: 2022-07-11 00:00:00.000000000 Z
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.1.6
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: