chewy.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # frozen_string_literal: true
  2. enabled = ENV['ES_ENABLED'] == 'true'
  3. host = ENV.fetch('ES_HOST') { 'localhost' }
  4. port = ENV.fetch('ES_PORT') { 9200 }
  5. user = ENV.fetch('ES_USER') { nil }
  6. password = ENV.fetch('ES_PASS') { nil }
  7. fallback_prefix = ENV.fetch('REDIS_NAMESPACE') { nil }
  8. prefix = ENV.fetch('ES_PREFIX') { fallback_prefix }
  9. Chewy.settings = {
  10. host: "#{host}:#{port}",
  11. prefix: prefix,
  12. enabled: enabled,
  13. journal: false,
  14. user: user,
  15. password: password,
  16. index: {
  17. number_of_replicas: ['single_node_cluster', nil].include?(ENV['ES_PRESET'].presence) ? 0 : 1,
  18. },
  19. }
  20. # We use our own async strategy even outside the request-response
  21. # cycle, which takes care of checking if Elasticsearch is enabled
  22. # or not. However, mind that for the Rails console, the :urgent
  23. # strategy is set automatically with no way to override it.
  24. Chewy.root_strategy = :bypass_with_warning if Rails.env.production?
  25. Chewy.request_strategy = :mastodon
  26. Chewy.use_after_commit_callbacks = false
  27. # Elasticsearch uses Faraday internally. Faraday interprets the
  28. # http_proxy env variable by default which leads to issues when
  29. # Mastodon is run with hidden services enabled, because
  30. # Elasticsearch is *not* supposed to be accessed through a proxy
  31. Faraday.ignore_env_proxy = true