1
0

chewy.rb 1.3 KB

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