Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
405d1613
Commit
405d1613
authored
Jul 31, 2019
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ES: Fix client loading and refreshing
Ensure various `client` method always provide up-to-date client
parent
33471d9f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
39 deletions
+40
-39
config/initializers/elastic_client_setup.rb
config/initializers/elastic_client_setup.rb
+4
-39
ee/lib/gem_extensions/elasticsearch/model/client.rb
ee/lib/gem_extensions/elasticsearch/model/client.rb
+36
-0
No files found.
config/initializers/elastic_client_setup.rb
View file @
405d1613
...
...
@@ -39,43 +39,8 @@ Gitlab.ee do
Elasticsearch
::
Model
::
Adapter
::
Multiple
::
Records
.
prepend
GemExtensions
::
Elasticsearch
::
Model
::
Adapter
::
Multiple
::
Records
Elasticsearch
::
Model
::
Indexing
::
InstanceMethods
.
prepend
GemExtensions
::
Elasticsearch
::
Model
::
Indexing
::
InstanceMethods
Elasticsearch
::
Model
::
Adapter
::
ActiveRecord
::
Importing
.
prepend
GemExtensions
::
Elasticsearch
::
Model
::
Adapter
::
ActiveRecord
::
Importing
module
Elasticsearch
module
Model
module
Client
# This mutex is only used to synchronize *creation* of a new client, so
# all including classes can share the same client instance
CLIENT_MUTEX
=
Mutex
.
new
cattr_accessor
:cached_client
cattr_accessor
:cached_config
module
ClassMethods
# Override the default ::Elasticsearch::Model::Client implementation to
# return a client configured from application settings. All including
# 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.
#
# @return [Elasticsearch::Transport::Client]
def
client
(
_client
=
nil
)
store
=
::
Elasticsearch
::
Model
::
Client
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
)
store
.
cached_config
=
config
end
end
store
.
cached_client
end
end
end
end
end
Elasticsearch
::
Model
::
Client
::
InstanceMethods
.
prepend
GemExtensions
::
Elasticsearch
::
Model
::
Client
Elasticsearch
::
Model
::
Client
::
ClassMethods
.
prepend
GemExtensions
::
Elasticsearch
::
Model
::
Client
Elasticsearch
::
Model
::
ClassMethods
.
prepend
GemExtensions
::
Elasticsearch
::
Model
::
Client
Elasticsearch
::
Model
.
singleton_class
.
prepend
GemExtensions
::
Elasticsearch
::
Model
::
Client
end
ee/lib/gem_extensions/elasticsearch/model/client.rb
0 → 100644
View file @
405d1613
# frozen_string_literal: true
# Override `__elasticsearch__.client` to
# return a client configured from application settings. All including
# 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.
module
GemExtensions
module
Elasticsearch
module
Model
module
Client
CLIENT_MUTEX
=
Mutex
.
new
cattr_accessor
:cached_client
cattr_accessor
:cached_config
def
client
(
_client
=
nil
)
store
=
::
GemExtensions
::
Elasticsearch
::
Model
::
Client
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
)
store
.
cached_config
=
config
end
end
store
.
cached_client
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment