Skip to content

Commit

Permalink
Solving #50 - memoize MySQL's max_allowed_packet instead of querying …
Browse files Browse the repository at this point in the history
…it every time you run .import
  • Loading branch information
seamusabshere committed Mar 20, 2012
1 parent 3dc99c3 commit b36259a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/activerecord-import/adapters/mysql_adapter.rb
Expand Up @@ -5,10 +5,12 @@ module ActiveRecord::Import::MysqlAdapter
# Returns the maximum number of bytes that the server will allow
# in a single packet
def max_allowed_packet # :nodoc:
result = execute( "SHOW VARIABLES like 'max_allowed_packet';" )
# original Mysql gem responds to #fetch_row while Mysql2 responds to #first
val = result.respond_to?(:fetch_row) ? result.fetch_row[1] : result.first[1]
val.to_i
@max_allowed_packet ||= begin
result = execute( "SHOW VARIABLES like 'max_allowed_packet';" )
# original Mysql gem responds to #fetch_row while Mysql2 responds to #first
val = result.respond_to?(:fetch_row) ? result.fetch_row[1] : result.first[1]
val.to_i
end
end

# Returns a generated ON DUPLICATE KEY UPDATE statement given the passed
Expand Down

0 comments on commit b36259a

Please sign in to comment.