activerecord-analyze 0.10.2 → 0.11.0

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: bb482e02b102f39912a33db2441ad138c265a5a164b0c5250a1c7529be158fac
4
+ data.tar.gz: 6425028186c884de0fdb1c897ad1a2c9419c2d039904ace3158650a540810946
5
5
  SHA512:
6
- metadata.gz: 5699bbab0ed4d533d1c62ce5e02d1e54f5868db437cffee62a1be5fb5a34ad7c91fbb758d26ee6f227cb222e67e391564afbd53eb1a6cf1b197d1dfd3cf18b80
7
- data.tar.gz: b4d2a4ab6b79780d3f55584353381904a8a86c7cfe0f311646326b33f229c01097e250fd02f6569e69ecc8fe6ba89767aa39eac7f44b38f869e5a2e99479f3e0
6
+ metadata.gz: c397a9790a1ee56652d2ab5fc300594054def2f1f9f091dfe8572883abfffa4d74079d0b5fbb1043a2d933fb399fe31ead2f8d117b314db951a4a68caf7b1656
7
+ data.tar.gz: 7bebc96dd4bc6a4fb4b3c257d980ae6007a6aea82567c9d19bd5c003011e15c01bb1b08654186e48c58d6a90e6ae443f68349f8166b94c80d2ba3c1d538086c2
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.0"
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,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,15 @@ describe "ActiveRecord analyze" do
50
50
  end
51
51
  end
52
52
 
53
+ describe "full_debug" do
54
+ it "works" do
55
+ result = User.all.analyze(full_debug: true)
56
+ expect(JSON.parse(result)[0].keys.sort).to eq [
57
+ "Execution Time", "Plan", "Planning Time", "Triggers"
58
+ ]
59
+ end
60
+ end
61
+
53
62
  describe "supports options" do
54
63
  it "works" do
55
64
  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.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-11 00:00:00.000000000 Z
11
+ date: 2022-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord