Running Actions in Bulk
We briefly talked about bulk actions when we saw a surprising BulkResult while unfollowing artists, but now we’re intentionally going to write one.
Imagine that Tunez is super popular, and one artist now has thousands or even tens of thousands of followers. If they release a new album, our SendNewAlbumNotifications change module would be responsible for creating tens of thousands of Notification records in the database. We could do that one at a time, iterating over the followers and calling a create action for each, but that would be really inefficient.
Instead, we can call the create action once, with a list of records to be created. Ash will run all of the pre-database logic, such as validations and changes, for each ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access