Kenny Meyer Kenny Meyer - 7 months ago 12
Ruby Question

How to add an activity to more than 1000 non-follower user feeds?

I am trying to add an activity to many user feeds which aren't following the activity actor. I was thinking about using the "to" field, but GetStream only allows to target up to 100 feeds.

In my application I have a "promotion" activity which should be seen on every user feed, but sometimes we also want to target a "promotion" to a specific group of users, filtered by a property on them.

A promotion has a user as an actor, but the promotion should still appear on another user's feed even if that user doesn't follow the actor.

Sometimes I want to send out a promotion to 80k users.

How could I solve this?

I am using the Ruby library, and the Rails integration.

Answer

As you correctly pointed out the to target is not suited for your use case. The amount of targets you can include in a request is limited to 100. Luckily Stream's API expose a batch operation to add the same activity to many feeds.

This is an advanced functionality which you can use from the API client, since you are using the Rails integration, you can do something like this:

client = StreamRails.client
activity = self.create_activity
client.add_to_many(activity, ["flat:1", "flat:2", "flat:3"])

Note that self in the code example is the instance of your activity model.

Comments