ruby-pg-extras 3.2.0 → 3.2.4

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: 3fd26a79ff47d4681d4e39888c8f1b362ff2c585c526c06b779e0fd84c3bdd7b
4
- data.tar.gz: c516bc6586e939a6bdf9c815823094a1e1b92ef30c3dcf7064eb9a2b3394a845
3
+ metadata.gz: 297e1a74d8dc954314ed77c2da55a95747e33e0b5157c8371cc0f76efe6b9566
4
+ data.tar.gz: c11d9386d656671bf2adb0e15457df3cc6015104c6e6ba2e0634c67ee1fcbbe0
5
5
  SHA512:
6
- metadata.gz: ecc8790295246456eb2ff3bd7025a08ed0a44b435bcf2af7070b35e2f081eeb302061e976a96d0ef5ef21422168637053fed1931687ec96d44e64f457ec21f51
7
- data.tar.gz: 4a87d50af4289473bbf40bfe1dfae20bb214feca969ff56b34b3f27ba9321b28c3415443c3374970747877e3d5b3c14c0780e4e3108cdbf757eb1e0426c088d8
6
+ metadata.gz: 2e3891c10419e58bc53e47394c12032fbcce5fdb68ac82bc98e38c4b7f98a07087899bb83861b783de449fe03153d062eaf4a252db1a6939245889b1435c1bb8
7
+ data.tar.gz: 9dbdf383fa6b81dbdcc09e79e7e88660b4a3c802559525c99f41757b8e46a0061c896b213f0b0aa7910b570c313f717f449dbd20a1da81fe7478652f45fba5a8
data/README.md CHANGED
@@ -112,6 +112,38 @@ Keep reading to learn about methods that `diagnose` uses under the hood.
112
112
 
113
113
  ## Available methods
114
114
 
115
+ ### `table_info`
116
+
117
+ 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.
118
+
119
+ ```ruby
120
+ RubyPGExtras.table_info(args: { table_name: "users" })
121
+
122
+ | Table name | Table size | Table cache hit | Indexes cache hit | Estimated rows | Sequential scans | Indexes scans |
123
+ +------------+------------+-------------------+--------------------+----------------+------------------+---------------+
124
+ | users | 2432 kB | 0.999966685701511 | 0.9988780464661853 | 16650 | 2128 | 512496 |
125
+
126
+ ```
127
+
128
+ ### `index_info`
129
+
130
+ 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.
131
+
132
+ ```ruby
133
+
134
+ RubyPGExtras.index_info(args: { table_name: "users" })
135
+
136
+ | Index name | Table name | Columns | Index size | Index scans | Null frac |
137
+ +-------------------------------+------------+----------------+------------+-------------+-----------+
138
+ | users_pkey | users | id | 1152 kB | 163007 | 0.00% |
139
+ | index_users_on_slack_id | users | slack_id | 1080 kB | 258870 | 0.00% |
140
+ | index_users_on_team_id | users | team_id | 816 kB | 70962 | 0.00% |
141
+ | index_users_on_uuid | users | uuid | 1032 kB | 0 | 0.00% |
142
+ | index_users_on_block_uuid | users | block_uuid | 776 kB | 19502 | 100.00% |
143
+ | index_users_on_api_auth_token | users | api_auth_token | 1744 kB | 156 | 0.00% |
144
+
145
+ ```
146
+
115
147
  ### `cache_hit`
116
148
 
117
149
  ```ruby
@@ -10,7 +10,6 @@ module RubyPGExtras
10
10
 
11
11
  def call(data)
12
12
  rows = data.sort do |el|
13
- p el
14
13
  el.fetch(:ok) ? 1 : -1
15
14
  end.map do |el|
16
15
  symbol = el.fetch(:ok) ? "√" : "x"
@@ -11,10 +11,13 @@ module RubyPGExtras
11
11
  else
12
12
  index_data.fetch("tablename") == table_name
13
13
  end
14
+ end.sort_by do |index_data|
15
+ index_data.fetch("tablename")
14
16
  end.map do |index_data|
15
17
  index_name = index_data.fetch("indexname")
18
+
16
19
  {
17
- index_name: index_data.fetch("indexname"),
20
+ index_name: index_name,
18
21
  table_name: index_data.fetch("tablename"),
19
22
  columns: index_data.fetch("columns").split(',').map(&:strip),
20
23
  index_size: index_size_data.find do |el|
@@ -25,7 +28,7 @@ module RubyPGExtras
25
28
  end.fetch("index_scans", "N/A"),
26
29
  null_frac: null_indexes_data.find do |el|
27
30
  el.fetch("index") == index_name
28
- end&.fetch("null_frac", "N/A") || "0.00%"
31
+ end&.fetch("null_frac", "N/A")&.strip || "0.00%"
29
32
  }
30
33
  end
31
34
  end
@@ -11,6 +11,8 @@ module RubyPGExtras
11
11
  else
12
12
  table_data.fetch("tablename") == table_name
13
13
  end
14
+ end.sort_by do |table_data|
15
+ table_data.fetch("tablename")
14
16
  end.map do |table_data|
15
17
  table_name = table_data.fetch("tablename")
16
18
 
@@ -28,7 +28,7 @@ module RubyPGExtras
28
28
  "Table cache hit",
29
29
  "Indexes cache hit",
30
30
  "Estimated rows",
31
- "Sequentail scans",
31
+ "Sequential scans",
32
32
  "Indexes scans"
33
33
  ],
34
34
  title: title,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyPGExtras
4
- VERSION = "3.2.0"
4
+ VERSION = "3.2.4"
5
5
  end
@@ -87,7 +87,7 @@ module RubyPGExtras
87
87
  end
88
88
  end
89
89
 
90
- def self.index_info(args:, in_format: :display_table)
90
+ def self.index_info(args: {}, in_format: :display_table)
91
91
  data = RubyPGExtras::IndexInfo.call(args[:table_name])
92
92
 
93
93
  if in_format == :display_table
@@ -101,7 +101,7 @@ module RubyPGExtras
101
101
  end
102
102
  end
103
103
 
104
- def self.table_info(args:, in_format: :display_table)
104
+ def self.table_info(args: {}, in_format: :display_table)
105
105
  data = RubyPGExtras::TableInfo.call(args[:table_name])
106
106
 
107
107
  if in_format == :display_table
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-pg-extras
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-15 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: pg