Commit e1f3b4b6 authored by Robert Speicher's avatar Robert Speicher

Wrap elastic_client_setup initializer in `ee` block

parent 9f9638a7
...@@ -2,43 +2,45 @@ ...@@ -2,43 +2,45 @@
require 'gitlab/current_settings' require 'gitlab/current_settings'
Elasticsearch::Model::Response::Records.prepend GemExtensions::Elasticsearch::Model::Response::Records Gitlab.ee do
Elasticsearch::Model::Adapter::Multiple::Records.prepend GemExtensions::Elasticsearch::Model::Adapter::Multiple::Records Elasticsearch::Model::Response::Records.prepend GemExtensions::Elasticsearch::Model::Response::Records
Elasticsearch::Model::Indexing::InstanceMethods.prepend GemExtensions::Elasticsearch::Model::Indexing::InstanceMethods Elasticsearch::Model::Adapter::Multiple::Records.prepend GemExtensions::Elasticsearch::Model::Adapter::Multiple::Records
Elasticsearch::Model::Indexing::InstanceMethods.prepend GemExtensions::Elasticsearch::Model::Indexing::InstanceMethods
module Elasticsearch
module Model module Elasticsearch
module Client module Model
# This mutex is only used to synchronize *creation* of a new client, so module Client
# all including classes can share the same client instance # This mutex is only used to synchronize *creation* of a new client, so
CLIENT_MUTEX = Mutex.new # all including classes can share the same client instance
CLIENT_MUTEX = Mutex.new
cattr_accessor :cached_client
cattr_accessor :cached_config cattr_accessor :cached_client
cattr_accessor :cached_config
module ClassMethods
# Override the default ::Elasticsearch::Model::Client implementation to module ClassMethods
# return a client configured from application settings. All including # Override the default ::Elasticsearch::Model::Client implementation to
# classes will use the same instance, which is refreshed automatically # return a client configured from application settings. All including
# if the settings change. # classes will use the same instance, which is refreshed automatically
# # if the settings change.
# _client is present to match the arity of the overridden method, where #
# it is also not used. # _client is present to match the arity of the overridden method, where
# # it is also not used.
# @return [Elasticsearch::Transport::Client] #
def client(_client = nil) # @return [Elasticsearch::Transport::Client]
store = ::Elasticsearch::Model::Client def client(_client = nil)
store = ::Elasticsearch::Model::Client
store::CLIENT_MUTEX.synchronize do
config = Gitlab::CurrentSettings.elasticsearch_config store::CLIENT_MUTEX.synchronize do
config = Gitlab::CurrentSettings.elasticsearch_config
if store.cached_client.nil? || config != store.cached_config
store.cached_client = ::Gitlab::Elastic::Client.build(config) if store.cached_client.nil? || config != store.cached_config
store.cached_config = config store.cached_client = ::Gitlab::Elastic::Client.build(config)
store.cached_config = config
end
end end
end
store.cached_client store.cached_client
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment