Bulk updating gem source index hangs


15-Oct-2017 10:42

My first attempt was the most straight-forward attempt… I’m taking the CSV file, looping over the records and saving them.(0.1ms) BEGIN Product Exists (0.6ms) SELECT 1 AS one FROM "products" WHERE "products"."sku" = '123' LIMIT 1 SQL (0.3ms) INSERT INTO "products" ("sku", "name", "origin", "msrp_cents", "created_at", "updated_at") VALUES (

My first attempt was the most straight-forward attempt… I’m taking the CSV file, looping over the records and saving them.(0.1ms) BEGIN Product Exists (0.6ms) SELECT 1 AS one FROM "products" WHERE "products"."sku" = '123' LIMIT 1 SQL (0.3ms) INSERT INTO "products" ("sku", "name", "origin", "msrp_cents", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" "sku", "123"], ["name", "n"], ["origin", "Russia"], ["msrp_cents", 1000], ["created_at", "2015-12-05 .896705"], ["updated_at", "2015-12-05 .896705" (6.1ms) COMMITWhat we don’t see is that there is a lot going on behind the scenes as well.

Rails is having to talk over TCP to the database four times for each record, plus it is having to build two different SQL statements, each time.

One of the big highlights here is namespacing our Javascript function.

While the chances are low that someone out there is going to have clone_downloadable_checkboxes_to in the global namespace too, it's always best to use proper namespaces.

We'll need some Javascript to show and hide it.

At this point, you might have noticed that we're submitting a form with no fields in it!

]]

end end end Our code is still having to connect to the database 50,000 times.

Keep in mind that in this case I’ve turned off validations entirely.