make sure redis command filters dates properly

also write the tests that i should have written a while ago for this
This commit is contained in:
Leo Hemsted
2018-04-05 15:11:29 +01:00
parent 730eff7e97
commit ba612b0f5b
4 changed files with 76 additions and 0 deletions

View File

@@ -504,7 +504,12 @@ def populate_redis_template_usage(service_id, day):
Recalculate and replace the stats in redis for a day.
To be used if redis data is lost for some reason.
"""
# the day variable is set to midnight of that day
assert current_app.config['REDIS_ENABLED']
start_time = get_london_midnight_in_utc(day)
end_time = get_london_midnight_in_utc(day + timedelta(days=1))
usage = {
str(row.template_id): row.count
for row in db.session.query(
@@ -512,6 +517,8 @@ def populate_redis_template_usage(service_id, day):
func.count().label('count')
).filter(
Notification.service_id == service_id,
Notification.created_at >= start_time,
Notification.created_at < end_time
).group_by(
Notification.template_id
)