r/Devvit • • 17d ago

Help Monitoring post/comment score effficiently?

There is searchPosts - so you can have a scheduled task to scan and fetch score.
But there is nothing for comments.

Regularly pulling "all" posts - tens of thousands, then fetching all the comments does not perform and is a horrible waste of resources.

Triggers don't help since score events don't apply there. And it seems the timeframe also does not work - score change does not update the comment/post update timestamp.

Has anyone found a more efficient way to handle that?

1 Upvotes

4 comments sorted by

1

u/emily_in_boots 17d ago

I do this currently using the api - doing a reddit.info pulls 100 at a time which isn’t too inefficient, but this is a major hole in devvit right now, and one the admins need to address. I use it to report downvoted content but with devvit, it’s not really possible to do that.

1

u/dustofdeath 17d ago

Figures.
This means i have to start doing what they are doing myself - storing and caching comment/post ids and timestamps in redis so i can fetch by the id-s directly.

1

u/emily_in_boots 17d ago

It's still not going to be as fast as the api but yeah, that's what you need to do.

The way I do it is to store in a db table the subreddit, id, and created_utc field. Then if I want to check for downvotes, I choose a time period (I have a way to do this that improves efficiency by focusing on recent ones) and then I use reddit.info to get 100 at a time.

1

u/Traditional_Cook3668 17d ago

We sidestepped the question for the leaderboard: we do not mirror Reddit's score at all. Our leaderboard is a Redis sorted set per day. zAdd(streakKey(day), { score, member: userId }) when somebody finishes, and zRange(streakKey(day), 0, 4) to read the top rows. One write, one read, no polling and no listing. It is also consistent with the score the game actually awarded, which matters because Reddit's score can move with downvotes and says nothing about game points.

If you genuinely need Reddit's score, then yes: keep the ids in Redis and fetch only those ids. reddit.info accepts a batch of t3_/t1_ ids, so one call per 100 known ids beats walking the subreddit and pulling everything. Two practical notes: store the id plus the created_utc you saw at creation time, because you know at creation which entries you will want to check later and how fresh they are; and poll on a widening window (often in the first hour, then every 10 minutes for a day, then stop). The score-change events not firing and the updated timestamps not moving are the real reason polling has to be id-based: nothing in the API tells you "this one changed", so you have to re-read the ids you care about.

One decision worth making early: do you need Reddit's score, or the game's own score? If it is for a leaderboard, your own score in Redis is both cheaper and less gameable. If it is for moderation such as downvote detection, the id-list plus reddit.info approach is the way, and one nightly job over the last N days is usually enough.