mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 15:31:15 -05:00
Optimise query to populate notification statuses
Investigation with EXPLAIN and EXPLAIN ANALYZE for the notification history table shows this is another instance of [1] but for the key type column. Swapping "!=" for "IN" solves the problem. [1]: https://github.com/alphagov/notifications-api/pull/3360
This commit is contained in:
@@ -10,6 +10,8 @@ from sqlalchemy.types import DateTime, Integer
|
|||||||
from app import db
|
from app import db
|
||||||
from app.dao.dao_utils import autocommit
|
from app.dao.dao_utils import autocommit
|
||||||
from app.models import (
|
from app.models import (
|
||||||
|
KEY_TYPE_NORMAL,
|
||||||
|
KEY_TYPE_TEAM,
|
||||||
KEY_TYPE_TEST,
|
KEY_TYPE_TEST,
|
||||||
NOTIFICATION_CANCELLED,
|
NOTIFICATION_CANCELLED,
|
||||||
NOTIFICATION_CREATED,
|
NOTIFICATION_CREATED,
|
||||||
@@ -72,7 +74,7 @@ def query_for_fact_status_data(table, start_date, end_date, notification_type, s
|
|||||||
table.created_at < end_date,
|
table.created_at < end_date,
|
||||||
table.notification_type == notification_type,
|
table.notification_type == notification_type,
|
||||||
table.service_id == service_id,
|
table.service_id == service_id,
|
||||||
table.key_type != KEY_TYPE_TEST
|
table.key_type.in_((KEY_TYPE_NORMAL, KEY_TYPE_TEAM)),
|
||||||
).group_by(
|
).group_by(
|
||||||
table.template_id,
|
table.template_id,
|
||||||
table.service_id,
|
table.service_id,
|
||||||
|
|||||||
Reference in New Issue
Block a user