Hi all,

I'm performing batch updates like so:

World.db.transaction do
  worlds = World
    .where(:id => updates.keys.sort!)
    .for_update
    .all

  worlds
    .each { |w| w.randomNumber = updates[w.id] }

  World.dataset
    .on_duplicate_key_update(:randomNumber)
    .multi_insert(worlds)
end

`updates` is a hash where the key is the PK of the record to be updated and 
the value is hopefully self-explanatory. I'm sorting the keys to prevent 
deadlock on the MySQL side and loading the models into memory with `#all` 
because the resultset is quite small and I'd like this to be as performant 
as possible.

My questions are as follows:

   - If I submit a PR to expose the `Dataset#on_duplicate_key_update` 
   method to Models, would it be accepted? I hate having to write 
   `Model.dataset`!
   - Is there a quick and easy way to mark my models as "clean" after the 
   batch update is successfully applied?
   - Are there any other style or performance suggestions you can make? 
   This is for some Sinatra/Sequel tests I'm working on for 
   FrameworkBenchmarks[1].

Thank you in advance,

Mike

   1. 
   
https://github.com/mwpastore/FrameworkBenchmarks/tree/sinatra-sequel-rbx/frameworks/Ruby/sinatra-sequel
   

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to