rails-pg-extras 5.2.0 → 5.2.2

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: f2e57fcbe05e1da9585d0fb8be92151ca284cede15b3a6aa9bb442b9af324900
4
- data.tar.gz: d658a121f536534d0208339e8734debf10c5b515a2d6a68d5dcbd2eddfcc5e42
3
+ metadata.gz: 831f887d91a8519dc968d3f612eb08059100e99d717db2a8ce6f0c13684d4714
4
+ data.tar.gz: f8da112789be789c8f1be7c7e11b27c94c5e8166e7096381cdfa726140fb3df4
5
5
  SHA512:
6
- metadata.gz: '08e240f5d4a8a61f991e35b37a4bae4216bd0cc260f03f8af911219df8e73dc7c8c891d435e4a63b82bd5e2ce7dca476b3ba98634946d614e9bd387e2134bd7f'
7
- data.tar.gz: 285ebd1cbce49cc3c17c8755bfc9775acedd7a098f0e69b7611faecd96b137dcd0f9f0e643a30a009af47ae3cc18bee1e2680670487ac42a4f5f378898059263
6
+ metadata.gz: 152d6244f1e32d32c3f98510b7316b224cc22c9e3a40ea84ce130e109335adf222f3e43391285dfd3e8c8ab51285a0b0933fe9529fabc2c4344ab2831b08bcbf
7
+ data.tar.gz: 51d26d67deaa392f3c8055f55cf6c0ac0e54dfa284eaf9445b59cb49ad14b7a47a0f2e0e057858bde2a1bace4309bd6aa17389b5804b8daf2cd0dba8e3506683
data/README.md CHANGED
@@ -51,7 +51,7 @@ You should see the similar line in the output:
51
51
  RailsPgExtras.add_extensions
52
52
  ```
53
53
 
54
- By deafult a primary ActiveRecord database connection is used for running metadata queries, rake tasks and web UI. To connect to a different database you can specify an `ENV['RAILS_PG_EXTRAS_DATABASE_URL']` value in the following format:
54
+ By default a primary ActiveRecord database connection is used for running metadata queries, rake tasks and web UI. To connect to a different database you can specify an `ENV['RAILS_PG_EXTRAS_DATABASE_URL']` value in the following format:
55
55
 
56
56
  ```ruby
57
57
  ENV["RAILS_PG_EXTRAS_DATABASE_URL"] = "postgresql://postgres:secret@localhost:5432/database_name"
@@ -148,44 +148,59 @@ This method displays query types executed when running a provided Ruby snippet,
148
148
 
149
149
  RailsPgExtras.measure_queries { User.limit(10).map(&:team) }
150
150
 
151
- # {:count=>11,
152
- # :queries=>
153
- # {"SELECT \"users\".* FROM \"users\" LIMIT $1"=>
154
- # {:count=>1,
155
- # :total_duration=>0.003183000022545457,
156
- # :min_duration=>0.003183000022545457,
157
- # :max_duration=>0.003183000022545457,
158
- # :avg_duration=>0.003183000022545457},
159
- # "SELECT \"teams\".* FROM \"teams\" WHERE \"teams\".\"id\" = $1 LIMIT $2"=>
160
- # {:count=>10,
161
- # :total_duration=>0.011682000011205673,
162
- # :min_duration=>0.0007209999894257635,
163
- # :max_duration=>0.0024030000204220414,
164
- # :avg_duration=>0.0011682000011205673}},
165
- # :total_duration=>0.15247199998702854,
166
- # :sql_duration=>0.01486500003375113}
151
+ {:count=>11,
152
+ :queries=>
153
+ {"SELECT \"users\".* FROM \"users\" LIMIT $1"=>
154
+ {:count=>1,
155
+ :total_duration=>1.9,
156
+ :min_duration=>1.9,
157
+ :max_duration=>1.9,
158
+ :avg_duration=>1.9},
159
+ "SELECT \"teams\".* FROM \"teams\" WHERE \"teams\".\"id\" = $1 LIMIT $2"=>
160
+ {:count=>10,
161
+ :total_duration=>0.94,
162
+ :min_duration=>0.62,
163
+ :max_duration=>1.37,
164
+ :avg_duration=>0.94}},
165
+ :total_duration=>13.35,
166
+ :sql_duration=>11.34}
167
167
 
168
168
  RailsPgExtras.measure_queries { User.limit(10).includes(:team).map(&:team) }
169
169
 
170
- # {:count=>2,
171
- # :queries=>
172
- # {"SELECT \"users\".* FROM \"users\" LIMIT $1"=>
173
- # {:count=>1,
174
- # :total_duration=>0.0036189999955240637,
175
- # :min_duration=>0.0036189999955240637,
176
- # :max_duration=>0.0036189999955240637,
177
- # :avg_duration=>0.0036189999955240637},
178
- # "SELECT \"teams\".* FROM \"teams\" WHERE \"teams\".\"id\" IN ($1, $2, $3, $4, $5, $6, $7, $8)"=>
179
- # {:count=>1,
180
- # :total_duration=>0.003714999998919666,
181
- # :min_duration=>0.003714999998919666,
182
- # :max_duration=>0.003714999998919666,
183
- # :avg_duration=>0.003714999998919666}},
184
- # :total_duration=>0.023814999993192032,
185
- # :sql_duration=>0.0073339999944437295}
170
+ {:count=>2,
171
+ :queries=>
172
+ {"SELECT \"users\".* FROM \"users\" LIMIT $1"=>
173
+ {:count=>1,
174
+ :total_duration=>3.43,
175
+ :min_duration=>3.43,
176
+ :max_duration=>3.43,
177
+ :avg_duration=>3.43},
178
+ "SELECT \"teams\".* FROM \"teams\" WHERE \"teams\".\"id\" IN ($1, $2, $3, $4, $5, $6, $7, $8)"=>
179
+ {:count=>1,
180
+ :total_duration=>2.59,
181
+ :min_duration=>2.59,
182
+ :max_duration=>2.59,
183
+ :avg_duration=>2.59}},
184
+ :total_duration=>9.75,
185
+ :sql_duration=>6.02}
186
186
 
187
187
  ```
188
188
 
189
+ Optionally, by including [Marginalia gem](https://github.com/basecamp/marginalia) and configuring it to display query backtraces:
190
+
191
+ `config/development.rb`
192
+
193
+ ```ruby
194
+
195
+ Marginalia::Comment.components = [:line]
196
+
197
+ ```
198
+
199
+ you can add this info to the output:
200
+
201
+ ![Marginalia logs](https://github.com/pawurb/rails-pg-extras/raw/master/marginalia-logs.png)
202
+
203
+
189
204
  ### `table_info`
190
205
 
191
206
  This method displays metadata metrics for all or a selected table. You can use it to check the table's size, its cache hit metrics, and whether it is correctly indexed. Many sequential scans or no index scans are potential indicators of misconfigured indexes. This method aggregates data provided by other methods in an easy to analyze summary format.
@@ -89,11 +89,11 @@ module RailsPgExtras
89
89
  sql_duration += duration
90
90
 
91
91
  if queries[key][:min_duration] == nil || queries[key][:min_duration] > duration
92
- queries[key][:min_duration] = duration
92
+ queries[key][:min_duration] = duration.round(2)
93
93
  end
94
94
 
95
95
  if queries[key][:max_duration] == nil || queries[key][:max_duration] < duration
96
- queries[key][:max_duration] = duration
96
+ queries[key][:max_duration] = duration.round(2)
97
97
  end
98
98
  end
99
99
  end
@@ -103,7 +103,8 @@ module RailsPgExtras
103
103
  end
104
104
 
105
105
  queries = queries.reduce({}) do |agg, val|
106
- val[1][:avg_duration] = val[1][:total_duration] / val[1][:count]
106
+ val[1][:avg_duration] = (val[1][:total_duration] / val[1][:count]).round(2)
107
+ val[1][:total_duration] = val[1][:total_duration].round(2)
107
108
  agg.merge(val[0] => val[1])
108
109
  end
109
110
 
@@ -111,11 +112,12 @@ module RailsPgExtras
111
112
  {
112
113
  count: queries.reduce(0) { |agg, val| agg + val[1].fetch(:count) },
113
114
  queries: queries,
114
- total_duration: total_duration,
115
- sql_duration: sql_duration
115
+ total_duration: total_duration.round(2),
116
+ sql_duration: sql_duration.round(2)
116
117
  }
117
118
  end
118
119
 
120
+
119
121
  def self.index_info(args: {}, in_format: :display_table)
120
122
  data = RailsPgExtras::IndexInfo.call(args[:table_name])
121
123
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsPgExtras
4
- VERSION = "5.2.0"
4
+ VERSION = "5.2.2"
5
5
  end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-pg-extras
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.0
4
+ version: 5.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-27 00:00:00.000000000 Z
11
+ date: 2023-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-pg-extras
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 5.2.0
19
+ version: 5.2.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 5.2.0
26
+ version: 5.2.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -106,6 +106,7 @@ files:
106
106
  - lib/rails_pg_extras/version.rb
107
107
  - lib/rails_pg_extras/web.rb
108
108
  - lib/rails_pg_extras/web/engine.rb
109
+ - marginalia-logs.png
109
110
  - pg-extras-ui.png
110
111
  - rails-pg-extras-diagnose.png
111
112
  - rails-pg-extras.gemspec