# Assign users a random digest time?

**URL:** https://meta.discourse.org/t/assign-users-a-random-digest-time/325639
**Category:** Support
**Tags:** email, activity-summary
**Created:** [September 9, 2024, 2:08pm UTC](https://meta.discourse.org/t/assign-users-a-random-digest-time/325639 "2024-09-09T14:08:16Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![GeoffSchultz](https://avatars.discourse-cdn.com/v4/letter/g/8491ac/32.png) [@GeoffSchultz](https://meta.discourse.org/u/GeoffSchultz)
#### Post date: [September 9, 2024, 2:08pm UTC](https://meta.discourse.org/t/assign-users-a-random-digest-time/325639/1 "2024-09-09T14:08:16Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### Post date: [September 9, 2024, 2:13pm UTC](https://meta.discourse.org/t/assign-users-a-random-digest-time/325639/2 "2024-09-09T14:13:16Z")

</div>

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

[https://ask.discourse.com/discourse-ai/ai-bot/shared-ai-conversations/wisnZ2lMtzSY1ji\_QM8BiA](https://ask.discourse.com/discourse-ai/ai-bot/shared-ai-conversations/wisnZ2lMtzSY1ji_QM8BiA)

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

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [September 9, 2024, 2:27pm UTC](https://meta.discourse.org/t/assign-users-a-random-digest-time/325639/3 "2024-09-09T14:27:18Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![GeoffSchultz](https://avatars.discourse-cdn.com/v4/letter/g/8491ac/32.png) [@GeoffSchultz](https://meta.discourse.org/u/GeoffSchultz)
#### Post date: [September 9, 2024, 8:10pm UTC](https://meta.discourse.org/t/assign-users-a-random-digest-time/325639/4 "2024-09-09T20:10:55Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [September 9, 2024, 8:15pm UTC](https://meta.discourse.org/t/assign-users-a-random-digest-time/325639/5 "2024-09-09T20:15:10Z")

</div>

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

But you could

```plaintext
./launcher enter app
su - postgres 
psql discourse

```

and have at it.

You can look at [Administrative Bulk Operations](https://meta.discourse.org/t/administrative-bulk-operations/118349) and, I think, find some examples that look like

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

```

---

<div class="post-metadata">

### Author: ![GeoffSchultz](https://avatars.discourse-cdn.com/v4/letter/g/8491ac/32.png) [@GeoffSchultz](https://meta.discourse.org/u/GeoffSchultz)
#### Post date: [September 10, 2024, 4:37pm UTC](https://meta.discourse.org/t/assign-users-a-random-digest-time/325639/6 "2024-09-10T16:37:20Z")

</div>

> [@pfaffman](#):
>
> `psql discourse`

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:

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

```

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [September 10, 2024, 5:27pm UTC](https://meta.discourse.org/t/assign-users-a-random-digest-time/325639/7 "2024-09-10T17:27:15Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![GeoffSchultz](https://avatars.discourse-cdn.com/v4/letter/g/8491ac/32.png) [@GeoffSchultz](https://meta.discourse.org/u/GeoffSchultz)
#### Post date: [September 12, 2024, 2:34pm UTC](https://meta.discourse.org/t/assign-users-a-random-digest-time/325639/8 "2024-09-12T14:34:36Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [October 12, 2024, 2:35pm UTC](https://meta.discourse.org/t/assign-users-a-random-digest-time/325639/9 "2024-10-12T14:35:08Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
