Skip to content

Commit

Permalink
Make column mappings name/type exclusive to a thread
Browse files Browse the repository at this point in the history
We have only seen it happen once, but columns were not being
mapped and it seems it was due to threading issues with the
mapper.

also updated .gitignore to igore .ruby-*
  • Loading branch information
abrandoned committed Feb 17, 2015
1 parent 8b69973 commit d1be39d
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 d1be39d

Please sign in to comment.