bustle
bustle copied to clipboard
Accept a collection of subscribers for Bustle::Subscriptions.add
Just logging a feature request here from observed use, will try to contribute, time allowing:
subscribers = @some_resource.followers
Bustle::Subscriptions.add(publisher, subscribers)
Seems like a natural API and a common situation.
However, with this particular example there's a subtle but big implication: subscribers
isn't an array of Bustle::Subscriber
objects already. It might nicely cut down on boilerplate if Bustle could recognize that and try to find/create appropriate Subscriber
instances behind the scenes. But that may be more complexity than you want to introduce, not sure, just a thought.
An incremental step might be:
subscribers = @some_resource.followers.map { |follower| Bustle::Subscribers.add follower }
Bustle::Subscriptions.add(publisher, subscribers)
But in that case it's not much of a win versus iterating through the followers and adding the Subscriber
and Subscription
within the block. Ideally somewhere along the way we could benefit from a bulk database operation instead of N+1.