Skip to content

Commit

Permalink
thread safe in TS:Index#attributes_types_map
Browse files Browse the repository at this point in the history
  • Loading branch information
bibendi committed Apr 22, 2013
1 parent fb5feee commit 41276f9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/sphinx/integration/extensions/thinking_sphinx/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ module Sphinx::Integration::Extensions::ThinkingSphinx::Index

included do
attr_accessor :merged_with_core, :is_core_index, :mva_sources
alias_method_chain :initialize, :mutex
alias_method_chain :to_riddle, :merged
alias_method_chain :to_riddle_for_distributed, :merged
alias_method_chain :all_names, :rt
end

def initialize_with_mutex(model, &block)
@mutex = Mutex.new
initialize_without_mutex(model, &block)
end

def to_riddle_with_merged(offset)
return [] if merged_with_core?

Expand Down Expand Up @@ -99,8 +105,10 @@ def all_names_with_rt
#
# Returns Hash
def attributes_types_map
return @attributes_type_map if defined?(@attributes_type_map)
@attributes_type_map = attributes.inject({}){ |h, attr| h[attr.unique_name.to_s] = attr.type; h }
@mutex.synchronize do
return @attributes_types_map if @attributes_types_map
@attributes_types_map = attributes.inject({}){ |h, attr| h[attr.unique_name.to_s] = attr.type; h }
end
end

def single_query_sql
Expand Down

0 comments on commit 41276f9

Please sign in to comment.