# חלון זמן התראות דחיפה דקות יכול להיות כפול מהזמן הזה

**URL:** https://meta.discourse.org/t/push-notification-time-window-mins-can-be-double-that-time/259688
**Category:** Bug
**Created:** [28 במרץ,‏ 2023,‏ 12:48pm UTC](https://meta.discourse.org/t/push-notification-time-window-mins-can-be-double-that-time/259688 "2023-03-28T12:48:28Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [28 במרץ,‏ 2023,‏ 12:48pm UTC](https://meta.discourse.org/t/push-notification-time-window-mins-can-be-double-that-time/259688/1 "2023-03-28T12:48:29Z")

</div>

Since we now FINALLY have push notifications on iOS PWA 🎉 I was looking into the delay that is applied before a push notification is being sent - because it seemed to take longer than expected.

The [code](https://github.com/discourse/discourse/blame/e636abeb0d92855cd97742a5d48d7018284106ee/app/services/post_alerter.rb#L57-L66) checks if a user was online recently (less than `push_notification_time_window_mins` ago) and if they were then the notification is delayed for `push_notification_time_window_mins`

```plaintext
      if user.seen_since?(SiteSetting.push_notification_time_window_mins.minutes.ago)
        Jobs.enqueue_in(
          SiteSetting.push_notification_time_window_mins.minutes,
          ...
        )
      else
        Jobs.enqueue(:send_push_notification, user_id: user.id, payload: payload)
      end

```

But this means that in practice this can take up to as twice as long as expected since the `push_notification_time_window_mins` is applied both in the online check as in the delay.

Example:

`push_notification_time_window_mins` is set to 10

**13:00**  
I leave the site  
**13:10**  
Something happens that triggers a notification.  
Code checks whether I was online less than 10 minutes ago.  
I was, so the notification will be sent at **13:20**.

**12:59**  
I leave the site  
**13:10**  
Something happens that triggers a notification.  
Code checks whether I was online less than 10 minutes ago.  
I was not, so the notification will be sent immediately, at **13:10**.

So one minute difference in my online time can change the notification delivery with almost `push_notification_time_window_mins`. Especially if the setting is changed into a higher value this can make a significant difference.

I would expect the delay to be push\_notification\_time\_window\_mins - (now - seen\_since)

---

_[View the full topic](https://meta.discourse.org/t/push-notification-time-window-mins-can-be-double-that-time/259688)._
