<commit_before>module PgHero
  class HomeController < ActionController::Base
    layout "pg_hero/application"

    protect_from_forgery

    http_basic_authenticate_with name: ENV["PGHERO_USERNAME"], password: ENV["PGHERO_PASSWORD"] if ENV["PGHERO_PASSWORD"]

    if respond_to?(:before_action)
      before_action :set_database
      before_action :set_query_stats_enabled
    else
      before_filter :set_database
      before_filter :set_query_stats_enabled
    end

    def index
      @title = "Overview"
      @extended = params[:extended]
      @query_stats = @database.query_stats(historical: true, start_at: 3.hours.ago)
      @slow_queries = @database.slow_queries(query_stats: @query_stats)
      @autovacuum_queries, @long_running_queries = @database.long_running_queries.partition { |q| q["query"].starts_with?("autovacuum:") }

      if @extended
        @index_hit_rate = @database.index_hit_rate
        @table_hit_rate = @database.table_hit_rate
        @good_cache_rate = @table_hit_rate >= @database.cache_hit_rate_threshold / 100 && @index_hit_rate >= @database.cache_hit_rate_threshold / 100
      end
<commit_msg>Fixed cache hit rate error<commit_after>module PgHero
  class HomeController < ActionController::Base
    layout "pg_hero/application"

    protect_from_forgery

    http_basic_authenticate_with name: ENV["PGHERO_USERNAME"], password: ENV["<PASSWORD>PASSWORD"] if ENV["PGHERO_PASSWORD"]

    if respond_to?(:before_action)
      before_action :set_database
      before_action :set_query_stats_enabled
    else
      before_filter :set_database
      before_filter :set_query_stats_enabled
    end

    def index
      @title = "Overview"
      @extended = params[:extended]
      @query_stats = @database.query_stats(historical: true, start_at: 3.hours.ago)
      @slow_queries = @database.slow_queries(query_stats: @query_stats)
      @autovacuum_queries, @long_running_queries = @database.long_running_queries.partition { |q| q["query"].starts_with?("autovacuum:") }

      if @extended
        @index_hit_rate = @database.index_hit_rate || 0
        @table_hit_rate = @database.table_hit_rate || 0
        @good_cache_rate = @table_hit_rate >= @database.cache_hit_rate_threshold / 100.0 && @index_hit_rate >= @database.cache_hit_rate_threshold / 100.0
      end

{'fraction_non_alphanumeric': 0.09643788010425716, 'fraction_numerical': 0.007819287576020852, 'mean_word_length': 4.222222222222222, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1072245', 'n_tokens_mistral': 787, 'n_tokens_neox': 740, 'n_words': 126}