Skip to content

Commit

Permalink
Merge pull request #14 from liveh2o/abrandoned/exclusive_the_column_m…
Browse files Browse the repository at this point in the history
…apping

Make column mappings name/type exclusive to a thread
  • Loading branch information
liveh2o committed Feb 19, 2015
2 parents 8b69973 + d1be39d commit 9afd652
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
.config
.rvmrc
.yardoc
.ruby-*
Gemfile.lock
coverage
pkg/*
Expand Down
22 changes: 12 additions & 10 deletions lib/protobuf/active_record/columns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,22 @@ def _protobuf_datetime_column?(key)
# Map out the columns for future reference on type conversion
# :nodoc:
def _protobuf_map_columns(force = false)
return unless table_exists?
::Thread.exclusive do
@_protobuf_mapped_columns = false if force

@_protobuf_mapped_columns = false if force
return if _protobuf_mapped_columns?
return unless table_exists?
return if _protobuf_mapped_columns?

@_protobuf_columns = {}
@_protobuf_column_types = Hash.new { |h,k| h[k] = [] }
@_protobuf_columns = {}
@_protobuf_column_types = Hash.new { |h,k| h[k] = [] }

columns.map do |column|
@_protobuf_columns[column.name.to_sym] = column
@_protobuf_column_types[column.type.to_sym] << column.name.to_sym
end
columns.map do |column|
@_protobuf_columns[column.name.to_sym] = column
@_protobuf_column_types[column.type.to_sym] << column.name.to_sym
end

@_protobuf_mapped_columns = true
@_protobuf_mapped_columns = true
end
end

def _protobuf_mapped_columns?
Expand Down

0 comments on commit 9afd652

Please sign in to comment.