Assign users a random digest time?

AI-generated summary

The discussion revolves around assigning users a random digest time in a Discourse forum. GeoffSchultz migrated a phpBB forum with 1400 users and noticed all digests were sent at 8 AM. He sought help to randomize the digest times between 00:00 and 23:00.

Pfaffman suggested modifying the user_stats.digest_attempted_at value by adding 0-24 hours to the current value. However, GeoffSchultz was unsure about connecting to the database on a DigitalOcean droplet.

Pfaffman provided guidance on accessing the database via Rails or using PostgreSQL. GeoffSchultz decided to use PostgreSQL and successfully updated the digest times using the query:

UPDATE user_stats SET digest_attempted_at = digest_attempted_at - interval '1' DAY * random();

Pfaffman confirmed the solution, and GeoffSchultz reported that the digest times are now spread out evenly.

I recently migrated a phpBB forum with about 1400 users to Discourse. Other than a handful of accounts, all of the digests seem to be sent starting at 8 AM. Is there some way to assign the users a random time between 00:00 and 23:00?

– Geoff

I don’t know but I was told (by AI):

https://ask.discourse.com/discourse-ai/ai-bot/shared-ai-conversations/wisnZ2lMtzSY1ji_QM8BiA

Click saver: no, if AI knew and wasn’t hallucinating.

I think that you could modify user_stats.digest_attempted_at for all of your users with a random value. Maybe you’d add 0-24 hours to their current user_stats.digest_attempted_at value.

This is what I kind of guessed that I would have to do. However, I’m used to shared-server environments where there’s a database server that I can remotely connect to. I’m very good at SQL, but I’m lost as how to connect to the database on a DigitalOcean droplet. Any pointers would be greatly appreciated.

You want to do it from Rails rather than modify the database directly.

But you could

./launcher enter app
su - postgres 
psql discourse

and have at it.

You can look at Administrative Bulk Operations and, I think, find some examples that look like

users=User.where(something)
users.each do |user|
   user.update(field: value)
end

Thank you very much for the pointers. I decided that doing it from Rails was too much of a learning curve, so I figured out how to do it via postgres. Here was my solution:

./launcher enter app
su - postgres 
psql discourse
UPDATE user_stats SET digest_attempted_at = digest_attempted_at - interval '1' DAY * random();

Looks right to me.

I think for this it’s safe enough. I understand the go-with-what-you-know approach but Rails gives you lots of protections (making sure stuff gets enforced and tables stay connected and so on).

Glad you got it sorted!

Checking the email logs, everything is now spread out evenly. Thanks for your help!