<commit_before>module Gitlab
  module CurrentSettings
    def current_application_settings
      if RequestStore.active?
        RequestStore.fetch(:current_application_settings) { ensure_application_settings! }
      else
        ensure_application_settings!
      end
    end

    delegate :sidekiq_throttling_enabled?, to: :current_application_settings

    def fake_application_settings(defaults = ApplicationSetting.defaults)
      FakeApplicationSettings.new(defaults)
    end

    private

    def ensure_application_settings!
      return in_memory_application_settings if ENV['IN_MEMORY_APPLICATION_SETTINGS'] == 'true'

      cached_application_settings || uncached_application_settings
    end

    def cached_application_settings
      begin
        ApplicationSetting.cached
      rescue ::Redis::BaseError, ::Errno::ENOENT
        # In case Redis isn't running or the Redis UNIX socket file is not available
      end
    end

    def uncached_application_settings
      return fake_application_settings unless connect_to_db?

      # This loads from the database into the cache, so handle Redis errors
      begin
        db_settings = ApplicationSetting.current
      rescue ::Redis::BaseError, ::Errno::ENOENT
        # In case Redis isn't running or the Redis UNIX socket file is not available
      end

      # If there are pending migrations, it's possible there are columns that
      # need to be added to the application settings. To prevent Rake tasks
      # and other callers from failing, use any loaded settings and return
      # defaults for missing columns.
      if ActiveRecord::Migrator.needs_migration?
        defaults = ApplicationSetting.defaults
        defaults.merge!(db_settings.attributes.symbolize_keys) if db_settings.present?
        return fake_application_settings(defaults)
      end

      return db_settings if db_settings.present?

      ApplicationSetting.create_from_defaults || in_memory_application_settings
    end
<commit_msg>Change references from ApplicationSetting to ::ApplicationSetting to make autoload happier<commit_after>module Gitlab
  module CurrentSettings
    def current_application_settings
      if RequestStore.active?
        RequestStore.fetch(:current_application_settings) { ensure_application_settings! }
      else
        ensure_application_settings!
      end
    end

    delegate :sidekiq_throttling_enabled?, to: :current_application_settings

    def fake_application_settings(defaults = ::ApplicationSetting.defaults)
      FakeApplicationSettings.new(defaults)
    end

    private

    def ensure_application_settings!
      return in_memory_application_settings if ENV['IN_MEMORY_APPLICATION_SETTINGS'] == 'true'

      cached_application_settings || uncached_application_settings
    end

    def cached_application_settings
      begin
        ::ApplicationSetting.cached
      rescue ::Redis::BaseError, ::Errno::ENOENT
        # In case Redis isn't running or the Redis UNIX socket file is not available
      end
    end

    def uncached_application_settings
      return fake_application_settings unless connect_to_db?

      # This loads from the database into the cache, so handle Redis errors
      begin
        db_settings = ::ApplicationSetting.current
      rescue ::Redis::BaseError, ::Errno::ENOENT
        # In case Redis isn't running or the Redis UNIX socket file is not available
      end

      # If there are pending migrations, it's possible there are columns that
      # need to be added to the application settings. To prevent Rake tasks
      # and other callers from failing, use any loaded settings and return
      # defaults for missing columns.
      if ActiveRecord::Migrator.needs_migration?
        defaults = ::ApplicationSetting.defaults
        defaults.merge!(db_settings.attributes.symbolize_keys) if db_settings.present?
        return fake_application_settings(defaults)
      end

      return db_settings if db_settings.present?

      ::ApplicationSetting.create_from_defaults || in_memory_application_settings
    end

{'fraction_non_alphanumeric': 0.04929751047572098, 'fraction_numerical': 0.0, 'mean_word_length': 3.4889380530973453, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4487607', 'n_tokens_mistral': 1027, 'n_tokens_neox': 995, 'n_words': 311}