Skip to content

Commit

Permalink
Removed memoization that could be an issue with threading. Updated RE…
Browse files Browse the repository at this point in the history
…ADME to reflect that the gem should be thread safe
  • Loading branch information
sunblaze committed Mar 19, 2015
1 parent abaec7f commit 2dc73bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This gem is primarily intended for MySQL databases not running in strict mode,
which can easily cause data loss. These problems are documented in
[DataLossTest](https://github.com/wvanbergen/activerecord-databasevalidations/blob/master/test/data_loss_test.rb)

Should be thread-safe. Please submit an issue or PR if you can prove otherwise.

## Installation

Add this line to your application's Gemfile:
Expand Down
17 changes: 7 additions & 10 deletions lib/active_record/database_validations/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@ module MySQL
}

def self.column_size_limit(column)
@column_size_limit ||= {}
@column_size_limit[column] ||= begin
column_type = column.sql_type.sub(/\(.*\z/, '').gsub(/\s/, '_').to_sym
type_limit = TYPE_LIMITS.fetch(column_type, {})
column_type = column.sql_type.sub(/\(.*\z/, '').gsub(/\s/, '_').to_sym
type_limit = TYPE_LIMITS.fetch(column_type, {})

[
column.limit || type_limit[:maximum],
type_limit[:type],
determine_encoding(column),
]
end
[
column.limit || type_limit[:maximum],
type_limit[:type],
determine_encoding(column),
]
end

def self.column_range(column)
Expand Down

0 comments on commit 2dc73bd

Please sign in to comment.