activerecord-analyze 0.3.0 → 0.4.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: d52550c794a58f382c5e5e1d1b78463bc0766969e5e3d7818b494bbf7027924e
4
- data.tar.gz: 2a884a86a595021e5afc2c43083bb51287db83a5ac56da1ff4a9fe985c35870b
3
+ metadata.gz: 5163e6745e43205926a1c88a02c4459bd3d9971dde022f5dd64c3368d2c72c13
4
+ data.tar.gz: f084b56b9a5b9c5ba1e6ae69e6653c01224287b6e0107ca97666cbd695c04b73
5
5
  SHA512:
6
- metadata.gz: 7e10b5364ed42150d2c41f49c3378f0f4e44e886e9f6100ccc073500ed5185e2d97c39f74c3922544ad36ec1f52c7d947ec1385e573bcf994e0c96af461913ad
7
- data.tar.gz: 7d531a91c688a6c0127cc55b16f253ccbc9ada4a67b382c7dbfa25694b20ce5e0d33e18ed8ba7d81d5745e6a626c8e2b5769f6a4af52231b28187e461cd07bff
6
+ metadata.gz: 10a11c9983859c51270ae38503e6f751b49f281c85c2f5fd7f28a7709f93d285e6288db8c00741e402f031771b1208c531a142ee28b2bcf5f84d8f14f84c8c18
7
+ data.tar.gz: 3669dc47d6dc8e4b1b63881d3bf61fa2d6eff4be1264dab55f77a98a6e55d98ebf22cd37e22b731f1d866954c20032f381d3577db168527d7490b88275037f98
data/README.md CHANGED
@@ -14,4 +14,4 @@ gem 'activerecord-analyze'
14
14
 
15
15
  ### Disclaimer
16
16
 
17
- It is a bit experimental and can break with new Rails release. As soon as [this pull request](https://github.com/rails/rails/pull/31374/) is merged it will be obsolete.
17
+ It is a bit experimental and can break with new Rails release.
@@ -2,9 +2,57 @@ module ActiveRecord
2
2
  module ConnectionAdapters
3
3
  module PostgreSQL
4
4
  module DatabaseStatements
5
- def analyze(arel, binds = [])
6
- sql = "EXPLAIN ANALYZE #{to_sql(arel, binds)}"
7
- PostgreSQL::ExplainPrettyPrinter.new.pp(exec_query(sql, "EXPLAIN ANALYZE", binds))
5
+ def analyze(arel, binds = [], opts = {})
6
+ format_sql = if fmt = opts[:format].presence
7
+ case fmt
8
+ when :json
9
+ "FORMAT JSON,"
10
+ when :yaml
11
+ "FORMAT YAML,"
12
+ when :text
13
+ "FORMAT TEXT,"
14
+ when :xml
15
+ "FORMAT XML,"
16
+ end
17
+ end
18
+
19
+ verbose_sql = if opts[:verbose] == true
20
+ ", VERBOSE"
21
+ end
22
+
23
+ costs_sql = if opts[:costs] == true
24
+ ", COSTS"
25
+ end
26
+
27
+ settings_sql = if opts[:settings] == true
28
+ ", SETTINGS"
29
+ end
30
+
31
+ buffers_sql = if opts[:buffers] == true
32
+ ", BUFFERS"
33
+ end
34
+
35
+ timing_sql = if opts[:timing] == true
36
+ ", TIMING"
37
+ end
38
+
39
+ summary_sql = if opts[:summary] == true
40
+ ", SUMMARY"
41
+ end
42
+
43
+ analyze_sql = if opts[:analyze] == false
44
+ ""
45
+ else
46
+ "ANALYZE"
47
+ end
48
+
49
+ opts_sql = "(#{format_sql} #{analyze_sql}#{verbose_sql}#{costs_sql}#{settings_sql}#{buffers_sql}#{timing_sql}#{summary_sql})"
50
+ .strip.gsub(/\s+/, " ")
51
+ .gsub(/\(\s?\s?\s?,/, "(")
52
+ .gsub(/\s,\s/, " ")
53
+
54
+ sql = "EXPLAIN #{opts_sql} #{to_sql(arel, binds)}"
55
+ PostgreSQL::ExplainPrettyPrinter.new.pp(exec_query(sql, "EXPLAIN #{opts_sql}".strip, binds))
8
56
  end
9
57
  end
10
58
  end
@@ -13,15 +61,15 @@ end
13
61
 
14
62
  module ActiveRecord
15
63
  class Relation
16
- def analyze
17
- exec_analyze(collecting_queries_for_explain { exec_queries })
64
+ def analyze(opts = {})
65
+ exec_analyze(collecting_queries_for_explain { exec_queries }, opts)
18
66
  end
19
67
  end
20
68
  end
21
69
 
22
70
  module ActiveRecord
23
71
  module Explain
24
- def exec_analyze(queries) # :nodoc:
72
+ def exec_analyze(queries, opts = {}) # :nodoc:
25
73
  str = queries.map do |sql, binds|
26
74
  msg = "EXPLAIN ANALYZE for: #{sql}".dup
27
75
  unless binds.empty?
@@ -29,7 +77,7 @@ module ActiveRecord
29
77
  msg << binds.map { |attr| render_bind(attr) }.inspect
30
78
  end
31
79
  msg << "\n"
32
- msg << connection.analyze(sql, binds)
80
+ msg << connection.analyze(sql, binds, opts)
33
81
  end.join("\n")
34
82
 
35
83
  # Overriding inspect to be more human readable, especially in the console.
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordAnalyze
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
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.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-19 00:00:00.000000000 Z
11
+ date: 2021-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -45,7 +45,7 @@ homepage: http://github.com/pawurb/activerecord-analyze
45
45
  licenses:
46
46
  - MIT
47
47
  metadata: {}
48
- post_install_message:
48
+ post_install_message:
49
49
  rdoc_options: []
50
50
  require_paths:
51
51
  - lib
@@ -60,8 +60,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  requirements: []
63
- rubygems_version: 3.0.6
64
- signing_key:
63
+ rubygems_version: 3.1.4
64
+ signing_key:
65
65
  specification_version: 4
66
66
  summary: Add EXPLAIN ANALYZE to Active Record query objects
67
67
  test_files: []