Skip to content

Commit

Permalink
Minor refactor (#45)
Browse files Browse the repository at this point in the history
Capitalize SQL keywords for easier reading

Eliminate one conditional portion by doing an assignment and nil check
in one statement (this is more of a style thing that not everyone is a
fan of)
  • Loading branch information
andyatkinson authored Dec 14, 2023
1 parent a6d34fb commit 7211b8b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/rails-pg-extras.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ module RailsPgExtras

def self.run_query(query_name:, in_format:, args: {})
if %i(calls outliers).include?(query_name)
pg_stat_statements_ver = RailsPgExtras.connection.execute("select installed_version from pg_available_extensions where name='pg_stat_statements'")
.to_a[0].fetch("installed_version", nil)
if pg_stat_statements_ver != nil
if Gem::Version.new(pg_stat_statements_ver) < Gem::Version.new(NEW_PG_STAT_STATEMENTS)
pg_stat_statements_version_sql = "SELECT installed_version
FROM pg_available_extensions
WHERE name = 'pg_stat_statements'"
if (version = RailsPgExtras.connection.execute(pg_stat_statements_version_sql)
.to_a[0].fetch("installed_version", nil))
if Gem::Version.new(version) < Gem::Version.new(NEW_PG_STAT_STATEMENTS)
query_name = "#{query_name}_legacy".to_sym
end
end
Expand Down

0 comments on commit 7211b8b

Please sign in to comment.