mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-22 11:47:42 +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
|
SELECT devices.id, apns_token, sandbox, active_until, grace_period_until
|
||||||
FROM devices
|
FROM devices
|
||||||
INNER JOIN devices_accounts ON devices.id = devices_accounts.device_id
|
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)
|
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
|
SELECT devices.id, apns_token, sandbox, active_until, grace_period_until
|
||||||
FROM devices
|
FROM devices
|
||||||
INNER JOIN devices_accounts ON devices.id = devices_accounts.device_id
|
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)
|
return p.fetch(ctx, query, id)
|
||||||
}
|
}
|
||||||
|
|
|
@ -314,6 +314,13 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
|
||||||
return
|
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
|
// Iterate backwards so we notify from older to newer
|
||||||
for i := msgs.Count - 1; i >= 0; i-- {
|
for i := msgs.Count - 1; i >= 0; i-- {
|
||||||
msg := msgs.Children[i]
|
msg := msgs.Children[i]
|
||||||
|
|
Loading…
Reference in a new issue