rails-pg-extras 3.1.0 → 3.2.5

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: 72d0aaefc019490d3c298c7114d34fc55cc0f0b236f5edf8710a4bed290d96a5
4
- data.tar.gz: bdcce61d6e4436aa74ca098c44d5e480c9a010aa246a375cf57be514e4c10c73
3
+ metadata.gz: 2c0a85db31ea8aee2a8c78dd5fa564d02f6a20be8ed2a98140cd9973fde8e9e9
4
+ data.tar.gz: 93a1281cc97ac17c82444302e26dace96cecb1ce0bc5b2ed2a03a5f0d3c91058
5
5
  SHA512:
6
- metadata.gz: 3004a52e1219060a9f82e7a84028a1ee042fa95b9ef3320f9f093bf1fc3909586ac1fc0f33fb75c417df1ddec6bbef6f31d2a1ebfd6fe71d99d7d8f2ff09e266
7
- data.tar.gz: 48cc602df378555e04ec157afdb447d702c8dfc26efb155dba6c35da221ca38c079c226997bf0fe1ea471c819d56e4612adddf410e0cdeaf48169ac828273a1d
6
+ metadata.gz: 84f337ffd1691a0051de367bc4c41a2538e8122cff8d07b112689d1110341ff4f5f4f48359e1354f4429649a2e9a4dded97b278824970758f4de3c73cac5a0a0
7
+ data.tar.gz: 71dd10a03afd078939382510f2e13fef4376d8c49ff4aa46a4a0d851134eb3dbc1372f83ca40694c5f794c9a233c7fa764f37f770b3c4e2b1c3192f7ede8093e
data/README.md CHANGED
@@ -113,6 +113,38 @@ Keep reading to learn about methods that `diagnose` uses under the hood.
113
113
 
114
114
  ## Available methods
115
115
 
116
+ ### `table_info`
117
+
118
+ 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.
119
+
120
+ ```ruby
121
+ RailsPGExtras.table_info(args: { table_name: "users" })
122
+
123
+ | Table name | Table size | Table cache hit | Indexes cache hit | Estimated rows | Sequential scans | Indexes scans |
124
+ +------------+------------+-------------------+--------------------+----------------+------------------+---------------+
125
+ | users | 2432 kB | 0.999966685701511 | 0.9988780464661853 | 16650 | 2128 | 512496 |
126
+
127
+ ```
128
+
129
+ ### `index_info`
130
+
131
+ This method returns summary info about database indexes. You can check index size, how often it is used and what percentage of its total size are NULL values. Like the previous method, it aggregates data from other helper methods in an easy-to-digest format.
132
+
133
+ ```ruby
134
+
135
+ RailsPGExtras.index_info(args: { table_name: "users" })
136
+
137
+ | Index name | Table name | Columns | Index size | Index scans | Null frac |
138
+ +-------------------------------+------------+----------------+------------+-------------+-----------+
139
+ | users_pkey | users | id | 1152 kB | 163007 | 0.00% |
140
+ | index_users_on_slack_id | users | slack_id | 1080 kB | 258870 | 0.00% |
141
+ | index_users_on_team_id | users | team_id | 816 kB | 70962 | 0.00% |
142
+ | index_users_on_uuid | users | uuid | 1032 kB | 0 | 0.00% |
143
+ | index_users_on_block_uuid | users | block_uuid | 776 kB | 19502 | 100.00% |
144
+ | index_users_on_api_auth_token | users | api_auth_token | 1744 kB | 156 | 0.00% |
145
+
146
+ ```
147
+
116
148
  ### `cache_hit`
117
149
 
118
150
  ```ruby
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsPGExtras
4
+ class IndexInfo < RubyPGExtras::IndexInfo
5
+ private
6
+
7
+ def query_module
8
+ RailsPGExtras
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsPGExtras
4
+ class IndexInfoPrint < RubyPGExtras::IndexInfoPrint
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsPGExtras
4
+ class TableInfo < RubyPGExtras::TableInfo
5
+ private
6
+
7
+ def query_module
8
+ RailsPGExtras
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsPGExtras
4
+ class TableInfoPrint < RubyPGExtras::TableInfoPrint
5
+ end
6
+ end
@@ -24,4 +24,14 @@ namespace :pg_extras do
24
24
  task diagnose: :establish_connection do
25
25
  RailsPGExtras.diagnose
26
26
  end
27
+
28
+ desc "Display tables metadata metrics"
29
+ task table_info: :establish_connection do
30
+ RailsPGExtras.table_info
31
+ end
32
+
33
+ desc "Display indexes metadata metrics"
34
+ task index_info: :establish_connection do
35
+ RailsPGExtras.index_info
36
+ end
27
37
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsPGExtras
4
- VERSION = "3.1.0"
4
+ VERSION = "3.2.5"
5
5
  end
@@ -4,6 +4,10 @@ require 'terminal-table'
4
4
  require 'ruby-pg-extras'
5
5
  require 'rails-pg-extras/diagnose_data'
6
6
  require 'rails-pg-extras/diagnose_print'
7
+ require 'rails-pg-extras/index_info'
8
+ require 'rails-pg-extras/index_info_print'
9
+ require 'rails-pg-extras/table_info'
10
+ require 'rails-pg-extras/table_info_print'
7
11
 
8
12
  module RailsPGExtras
9
13
  QUERIES = RubyPGExtras::QUERIES
@@ -58,6 +62,34 @@ module RailsPGExtras
58
62
  end
59
63
  end
60
64
 
65
+ def self.index_info(args: {}, in_format: :display_table)
66
+ data = RailsPGExtras::IndexInfo.call(args[:table_name])
67
+
68
+ if in_format == :display_table
69
+ RailsPGExtras::IndexInfoPrint.call(data)
70
+ elsif in_format == :hash
71
+ data
72
+ elsif in_format == :array
73
+ data.map(&:values)
74
+ else
75
+ raise "Invalid 'in_format' argument!"
76
+ end
77
+ end
78
+
79
+ def self.table_info(args: {}, in_format: :display_table)
80
+ data = RailsPGExtras::TableInfo.call(args[:table_name])
81
+
82
+ if in_format == :display_table
83
+ RailsPGExtras::TableInfoPrint.call(data)
84
+ elsif in_format == :hash
85
+ data
86
+ elsif in_format == :array
87
+ data.map(&:values)
88
+ else
89
+ raise "Invalid 'in_format' argument!"
90
+ end
91
+ end
92
+
61
93
  def self.connection
62
94
  ActiveRecord::Base.connection
63
95
  end
data/spec/smoke_spec.rb CHANGED
@@ -13,4 +13,18 @@ describe RailsPGExtras do
13
13
  end.not_to raise_error
14
14
  end
15
15
  end
16
+
17
+ it "runs the custom methods" do
18
+ expect do
19
+ RailsPGExtras.diagnose(in_format: :hash)
20
+ end.not_to raise_error
21
+
22
+ expect do
23
+ RailsPGExtras.index_info(in_format: :hash)
24
+ end.not_to raise_error
25
+
26
+ expect do
27
+ RailsPGExtras.table_info(in_format: :hash)
28
+ end.not_to raise_error
29
+ end
16
30
  end
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: 3.1.0
4
+ version: 3.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-29 00:00:00.000000000 Z
11
+ date: 2021-12-21 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: 3.1.0
19
+ version: 3.2.5
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: 3.1.0
26
+ version: 3.2.5
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -85,7 +85,11 @@ files:
85
85
  - lib/rails-pg-extras.rb
86
86
  - lib/rails-pg-extras/diagnose_data.rb
87
87
  - lib/rails-pg-extras/diagnose_print.rb
88
+ - lib/rails-pg-extras/index_info.rb
89
+ - lib/rails-pg-extras/index_info_print.rb
88
90
  - lib/rails-pg-extras/railtie.rb
91
+ - lib/rails-pg-extras/table_info.rb
92
+ - lib/rails-pg-extras/table_info_print.rb
89
93
  - lib/rails-pg-extras/tasks/all.rake
90
94
  - lib/rails-pg-extras/version.rb
91
95
  - rails-pg-extras-diagnose.png
@@ -112,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
116
  - !ruby/object:Gem::Version
113
117
  version: '0'
114
118
  requirements: []
115
- rubygems_version: 3.1.6
119
+ rubygems_version: 3.0.3
116
120
  signing_key:
117
121
  specification_version: 4
118
122
  summary: Rails PostgreSQL performance database insights