Skip to content

Commit 1d71fba

Browse files
miguelffkarmi
authored andcommitted
[MODEL] Minor improvements to the multimodel search
Registry is not an array Modify _types to only iterate to necessary models Related: elastic#10, elastic#30, elastic#50, elastic#129, elastic#346
1 parent 6dd4972 commit 1d71fba

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Diff for: elasticsearch-model/lib/elasticsearch/model.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ module Model
7070

7171
# Keeps a registry of the classes that include `Elasticsearch::Model`
7272
#
73-
class Registry < Array
73+
class Registry
7474

7575
# Add the class of a model to the registry
7676
#

Diff for: elasticsearch-model/lib/elasticsearch/model/adapters/multiple.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ def __ids_by_type
9797
# A simple class-level memoization over the `_index` and `_type` properties of the hit is applied.
9898
# Hence querying the Model Registry is done the minimal amount of times.
9999
#
100+
# Event though memoization happens at the class level, the side effect of a race condition will only be
101+
# to iterate over models one extra time, so we can consider the method thread-safe, and don't include
102+
# any Mutex.synchronize around the method implementaion
103+
#
100104
# @see Elasticsearch::Model::Registry
101105
#
102106
# @return Class
@@ -106,7 +110,7 @@ def __ids_by_type
106110
def __type(hit)
107111
@@__types ||= {}
108112
@@__types[[hit[:_index], hit[:_type]].join("::")] ||= begin
109-
Registry.all.detect { |model| model.index_name == hit[:_index] && model.document_type == hit[:_type] }
113+
models.detect { |model| model.index_name == hit[:_index] && model.document_type == hit[:_type] }
110114
end
111115
end
112116

0 commit comments

Comments
 (0)