Add ES_PRESET
option to customize numbers of shards and replicas (#26483)
Co-authored-by: Eugen Rochko <eugen@zeonfederated.com>
This commit is contained in:
parent
30f84f10b1
commit
6c6f3c9148
8 changed files with 35 additions and 12 deletions
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AccountsIndex < Chewy::Index
|
||||
settings index: { refresh_interval: '30s' }, analysis: {
|
||||
settings index: index_preset(refresh_interval: '30s'), analysis: {
|
||||
filter: {
|
||||
english_stop: {
|
||||
type: 'stop',
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class InstancesIndex < Chewy::Index
|
||||
settings index: { refresh_interval: '30s' }
|
||||
settings index: index_preset(refresh_interval: '30s')
|
||||
|
||||
index_scope ::Instance.searchable
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
class StatusesIndex < Chewy::Index
|
||||
include FormattingHelper
|
||||
|
||||
settings index: { refresh_interval: '30s' }, analysis: {
|
||||
settings index: index_preset(refresh_interval: '30s', number_of_shards: 5), analysis: {
|
||||
filter: {
|
||||
english_stop: {
|
||||
type: 'stop',
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class TagsIndex < Chewy::Index
|
||||
settings index: { refresh_interval: '30s' }, analysis: {
|
||||
settings index: index_preset(refresh_interval: '30s'), analysis: {
|
||||
analyzer: {
|
||||
content: {
|
||||
tokenizer: 'keyword',
|
||||
|
|
|
@ -41,6 +41,8 @@ require_relative '../lib/mastodon/rack_middleware'
|
|||
require_relative '../lib/public_file_server_middleware'
|
||||
require_relative '../lib/devise/two_factor_ldap_authenticatable'
|
||||
require_relative '../lib/devise/two_factor_pam_authenticatable'
|
||||
require_relative '../lib/chewy/settings_extensions'
|
||||
require_relative '../lib/chewy/index_extensions'
|
||||
require_relative '../lib/chewy/strategy/mastodon'
|
||||
require_relative '../lib/chewy/strategy/bypass_with_warning'
|
||||
require_relative '../lib/webpacker/manifest_extensions'
|
||||
|
|
|
@ -25,14 +25,6 @@ Chewy.root_strategy = :bypass_with_warning if Rails.env.production?
|
|||
Chewy.request_strategy = :mastodon
|
||||
Chewy.use_after_commit_callbacks = false
|
||||
|
||||
module Chewy
|
||||
class << self
|
||||
def enabled?
|
||||
settings[:enabled]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Elasticsearch uses Faraday internally. Faraday interprets the
|
||||
# http_proxy env variable by default which leads to issues when
|
||||
# Mastodon is run with hidden services enabled, because
|
||||
|
|
18
lib/chewy/index_extensions.rb
Normal file
18
lib/chewy/index_extensions.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Chewy
|
||||
module IndexExtensions
|
||||
def index_preset(base_options = {})
|
||||
case ENV['ES_PRESET'].presence
|
||||
when 'single_node_cluster', nil
|
||||
base_options.merge(number_of_replicas: 0)
|
||||
when 'small_cluster'
|
||||
base_options.merge(number_of_replicas: 1)
|
||||
when 'large_cluster'
|
||||
base_options.merge(number_of_replicas: 1, number_of_shards: (base_options[:number_of_shards] || 1) * 2)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Chewy::Index.extend(Chewy::IndexExtensions)
|
11
lib/chewy/settings_extensions.rb
Normal file
11
lib/chewy/settings_extensions.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Chewy
|
||||
module SettingsExtensions
|
||||
def enabled?
|
||||
settings[:enabled]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Chewy.extend(Chewy::SettingsExtensions)
|
Loading…
Reference in a new issue