by lobo_tuerto on 1/25/24, 1:56 AM with 1 comments
by bhaney on 1/25/24, 3:33 AM
If you're aggregating a collection of results from remote nodes into a stream that transforms each one as they come in into a group of potentially inter-dependent queries that might not need to run at all, then you might want to reduce over that stream and accumulate into a Multi, then maybe even discard the whole Multi if a critical remote node dies in the middle or the results just aren't useful. If you try to use a Repo.transaction function for that, you're either wasting database resources by running half a doomed transaction and rolling back, or you're hand-rolling a "collection" of yet-to-be-run queries (and essentially reinventing Multi).
Multis are specifically for grouping and manipulating a plan of execution. They are not meant to be Ecto's general interface to transactions, and of course you're going to end up with frequently awkward code if you use them like that.