mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-22 03:37:43 +00:00
short circuit on notifications job
This commit is contained in:
parent
e5670c9828
commit
88a3e0a21f
2 changed files with 13 additions and 2 deletions
|
@ -90,7 +90,9 @@ func (p *postgresDeviceRepository) GetInboxNotifiableByAccountID(ctx context.Con
|
|||
SELECT devices.id, apns_token, sandbox, active_until, grace_period_until
|
||||
FROM devices
|
||||
INNER JOIN devices_accounts ON devices.id = devices_accounts.device_id
|
||||
WHERE devices_accounts.account_id = $1 AND devices_accounts.inbox_notifiable = TRUE`
|
||||
WHERE devices_accounts.account_id = $1 AND
|
||||
devices_accounts.inbox_notifiable = TRUE AND
|
||||
grace_period_until > NOW()`
|
||||
|
||||
return p.fetch(ctx, query, id)
|
||||
}
|
||||
|
@ -100,7 +102,9 @@ func (p *postgresDeviceRepository) GetWatcherNotifiableByAccountID(ctx context.C
|
|||
SELECT devices.id, apns_token, sandbox, active_until, grace_period_until
|
||||
FROM devices
|
||||
INNER JOIN devices_accounts ON devices.id = devices_accounts.device_id
|
||||
WHERE devices_accounts.account_id = $1 AND devices_accounts.watcher_notifiable = TRUE`
|
||||
WHERE devices_accounts.account_id = $1 AND
|
||||
devices_accounts.watcher_notifiable = TRUE AND
|
||||
grace_period_until > NOW()`
|
||||
|
||||
return p.fetch(ctx, query, id)
|
||||
}
|
||||
|
|
|
@ -314,6 +314,13 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
|
|||
return
|
||||
}
|
||||
|
||||
if len(devices) == 0 {
|
||||
nc.logger.WithFields(logrus.Fields{
|
||||
"account#username": account.NormalizedUsername(),
|
||||
}).Debug("no notifiable devices, finishing job")
|
||||
return
|
||||
}
|
||||
|
||||
// Iterate backwards so we notify from older to newer
|
||||
for i := msgs.Count - 1; i >= 0; i-- {
|
||||
msg := msgs.Children[i]
|
||||
|
|
Loading…
Reference in a new issue