mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-26 12:38:31 -04:00
Merge pull request #3014 from alphagov/get-query-in-50k-batches
Optimise dao_get_letters_to_be_printed query
This commit is contained in:
@@ -1688,10 +1688,20 @@ def test_letters_to_be_printed_sort_by_service(notify_db_session):
|
||||
second_service = create_service(service_name='second service', service_id='642bf33b-54b5-45f2-8c13-942a46616704')
|
||||
first_template = create_template(service=first_service, template_type='letter', postage='second')
|
||||
second_template = create_template(service=second_service, template_type='letter', postage='second')
|
||||
notification_1 = create_notification(template=first_template, created_at=datetime(2020, 12, 1, 9, 30))
|
||||
notification_2 = create_notification(template=first_template, created_at=datetime(2020, 12, 1, 12, 30))
|
||||
notification_3 = create_notification(template=second_template, created_at=datetime(2020, 12, 1, 8, 30))
|
||||
letters_ordered_by_service_then_time = [
|
||||
create_notification(template=first_template, created_at=datetime(2020, 12, 1, 9, 30)),
|
||||
create_notification(template=first_template, created_at=datetime(2020, 12, 1, 12, 30)),
|
||||
create_notification(template=first_template, created_at=datetime(2020, 12, 1, 13, 30)),
|
||||
create_notification(template=first_template, created_at=datetime(2020, 12, 1, 14, 30)),
|
||||
create_notification(template=first_template, created_at=datetime(2020, 12, 1, 15, 30)),
|
||||
create_notification(template=second_template, created_at=datetime(2020, 12, 1, 8, 30)),
|
||||
create_notification(template=second_template, created_at=datetime(2020, 12, 1, 8, 31)),
|
||||
create_notification(template=second_template, created_at=datetime(2020, 12, 1, 8, 32)),
|
||||
create_notification(template=second_template, created_at=datetime(2020, 12, 1, 8, 33)),
|
||||
create_notification(template=second_template, created_at=datetime(2020, 12, 1, 8, 34))
|
||||
]
|
||||
|
||||
results = list(dao_get_letters_to_be_printed(print_run_deadline=datetime(2020, 12, 1, 17, 30), postage='second'))
|
||||
assert len(results) == 3
|
||||
assert results == [notification_1, notification_2, notification_3]
|
||||
results = list(
|
||||
dao_get_letters_to_be_printed(print_run_deadline=datetime(2020, 12, 1, 17, 30), postage='second', query_limit=4)
|
||||
)
|
||||
assert [x.id for x in results] == [x.id for x in letters_ordered_by_service_then_time]
|
||||
|
||||
Reference in New Issue
Block a user