How would I go about updating 7000 or so rows of my database with
unique values? (In other words, I’m not setting them all to NULL or
incrementing or something… each row gets a new, special value.)
But I can’t seem to get my rails app to do this in less than 7000
connections to the database! I’ve looked very hard (3 horus!), and
can’t find anything about buffering calls to the database, to be done
all at once (much to my surprise).
ActiveRecord::Base.connection.execute ‘UPDATE things SET bar = 2, baz
= 8 WHERE id = 1; UPDATE things SET bar = 19, baz = 47 WHERE id = 2’
(but much longer).
But it doesn’t work… it doesn’t like the semicolon.
Is there really no way to do this? The problem I’m trying to solve is
that sometimes the acts_as_nested_set data needs updating completely,
but calling add_child on each item individually makes O(n*n)
connections. I can reduce it to O(n) connections, and it went from
taking 25 minutes to only 2 minutes… but I really need to get this
down to a few seconds.
Thanks so much,