File tree Expand file tree Collapse file tree 2 files changed +12
-7
lines changed
elasticsearch-model/lib/elasticsearch/model Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -106,16 +106,16 @@ def __ids_by_type
106
106
# @api private
107
107
#
108
108
def __type_for_hit ( hit )
109
- @@__types ||= { }
110
109
111
110
key = "#{ hit [ :_index ] } ::#{ hit [ :_type ] } " if hit [ :_type ] && hit [ :_type ] != '_doc'
112
111
key = hit [ :_index ] unless key
113
112
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 ] )
119
119
end
120
120
end
121
121
Original file line number Diff line number Diff line change @@ -48,7 +48,12 @@ def self.all
48
48
# Adds a model to the registry
49
49
#
50
50
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
52
57
end
53
58
54
59
# Returns a copy of the registered models
You can’t perform that action at this time.
0 commit comments