Skip to content

Commit 81536dd

Browse files
committed
Addressing elastic#838, STI issues when code is reloaded in development, fix index name to klass lookup methodology
1 parent 8fe0a55 commit 81536dd

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

elasticsearch-model/lib/elasticsearch/model/adapters/multiple.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,16 @@ def __ids_by_type
106106
# @api private
107107
#
108108
def __type_for_hit(hit)
109-
@@__types ||= {}
110109

111110
key = "#{hit[:_index]}::#{hit[:_type]}" if hit[:_type] && hit[:_type] != '_doc'
112111
key = hit[:_index] unless key
113112

114-
@@__types[key] ||= begin
115-
Registry.all.detect do |model|
116-
(model.index_name == hit[:_index] && __no_type?(hit)) ||
117-
(model.index_name == hit[:_index] && model.document_type == hit[:_type])
118-
end
113+
# DVB -- not sure the ramifications of this - but do not memoize the model/klass
114+
# I do not think that caching the types is necessary, minimal processing savings
115+
# at the expense of broken STI autoloading in development, see #848
116+
Registry.all.detect do |model|
117+
(model.index_name == hit[:_index] && __no_type?(hit)) ||
118+
(model.index_name == hit[:_index] && model.document_type == hit[:_type])
119119
end
120120
end
121121

elasticsearch-model/lib/elasticsearch/model/multimodel.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ def self.all
4848
# Adds a model to the registry
4949
#
5050
def add(klass)
51-
@models << klass
51+
# Detect already loaded models and ensure that a duplicate is not stored
52+
if i = @models.index{ |_class| _class.name == klass.name }
53+
@models[i] = klass
54+
else
55+
@models << klass
56+
end
5257
end
5358

5459
# Returns a copy of the registered models

0 commit comments

Comments
 (0)