lib/pghero/methods/query_stats.rb in pghero-1.3.2 vs lib/pghero/methods/query_stats.rb in pghero-1.4.0
- old
+ new
@@ -29,15 +29,20 @@
def query_stats_available?
select_all("SELECT COUNT(*) AS count FROM pg_available_extensions WHERE name = 'pg_stat_statements'").first["count"].to_i > 0
end
def query_stats_enabled?
- select_all("SELECT COUNT(*) AS count FROM pg_extension WHERE extname = 'pg_stat_statements'").first["count"].to_i > 0 && query_stats_readable?
+ query_stats_extension_enabled? && query_stats_readable?
end
+ def query_stats_extension_enabled?
+ select_all("SELECT COUNT(*) AS count FROM pg_extension WHERE extname = 'pg_stat_statements'").first["count"].to_i > 0
+ end
+
def query_stats_readable?
- select_all("SELECT has_table_privilege(current_user, 'pg_stat_statements', 'SELECT')").first["has_table_privilege"] == "t"
+ select_all("SELECT * FROM pg_stat_statements LIMIT 1")
+ true
rescue ActiveRecord::StatementInvalid
false
end
def enable_query_stats
@@ -114,11 +119,11 @@
end
# http://stackoverflow.com/questions/20582500/how-to-check-if-a-table-exists-in-a-given-schema
def historical_query_stats_enabled?
# TODO use schema from config
- stats_connection.select_all(squish <<-SQL
+ truthy? stats_connection.select_all(squish <<-SQL
SELECT EXISTS (
SELECT
1
FROM
pg_catalog.pg_class c
@@ -128,10 +133,10 @@
n.nspname = 'public'
AND c.relname = 'pghero_query_stats'
AND c.relkind = 'r'
)
SQL
- ).to_a.first["exists"] == "t"
+ ).to_a.first["exists"]
end
def stats_connection
::PgHero::QueryStats.connection
end