top | item 43881555

(no title)

drx | 10 months ago

Rails has ActiveRecord, which has an extremely elegant REPL. It's a delight to use.

discuss

order

karmakaze|10 months ago

ActiveRecord may be both the best and worst part of Rails. Currently the largest scaling problem that I'm facing is with all the before_* and after_* callbacks which run per model record rather than a batch of changed records. This is an N+1 query landmine field for which ActiveRecord offers no solutions.

benblue|10 months ago

I agree that ActiveRecord isn't particularly opinionated about how to deal with updates to batches of records, but there are multiple ways of approaching this and AR won't get in your way.

upsert_all[1] is available to update a batch of records in a single write that does not invoke model callbacks.

activerecord-import[2] is also very nice gem that provides a great api for working with batches of records.

It can be as simple as extracting your callback logic and a method (def self.batch_update) and running your callback logic after the upsert.

[1] https://api.rubyonrails.org/classes/ActiveRecord/Relation.ht... [2] https://github.com/zdennis/activerecord-import

cpursley|10 months ago

AR is the worst thing about Rails - it's anti-pattern central. The Ruby REPL is amazing, however.

Thaxll|10 months ago

ActiveRecord or how to badly couple your storage with your objetcs.