mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-05 16:58:25 -04:00
This PR optimises the queries for notification by reference.
By added the notification_type to the filter we get a better performance on the query. Especially when selecting for NotificationHistory.
This commit is contained in:
@@ -650,33 +650,29 @@ def dao_get_notifications_by_recipient_or_reference(
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def dao_get_notification_by_reference(reference):
|
||||
def dao_get_notification_by_reference(reference, notification_type):
|
||||
return Notification.query.filter(
|
||||
Notification.reference == reference
|
||||
Notification.reference == reference,
|
||||
Notification.notification_type == notification_type
|
||||
).one()
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def dao_get_notification_or_history_by_reference(reference):
|
||||
def dao_get_notification_or_history_by_reference(reference, notification_type):
|
||||
try:
|
||||
# This try except is necessary because in test keys and research mode does not create notification history.
|
||||
# Otherwise we could just search for the NotificationHistory object
|
||||
return Notification.query.filter(
|
||||
Notification.reference == reference
|
||||
Notification.reference == reference,
|
||||
Notification.notification_type == notification_type
|
||||
).one()
|
||||
except NoResultFound:
|
||||
return NotificationHistory.query.filter(
|
||||
NotificationHistory.reference == reference
|
||||
NotificationHistory.reference == reference,
|
||||
NotificationHistory.notification_type == notification_type
|
||||
).one()
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def dao_get_notifications_by_references(references):
|
||||
return Notification.query.filter(
|
||||
Notification.reference.in_(references)
|
||||
).all()
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def dao_created_scheduled_notification(scheduled_notification):
|
||||
db.session.add(scheduled_notification)
|
||||
|
||||
Reference in New Issue
Block a user