Added Scheduled task to get stats for template usage

Currently some pages are timing out due to the time it takes to perform
database queries. This is an attempt to improve the performance by
performing the query against the notification history table once a day
and use the notification table for a delta between midnight and the when
the page is run and combine the results.

- Added Celery task for doing the work
- Added a dao to handle the insert and update of the stats table
- Updated tests to test the new functionality
This commit is contained in:
Richard Chapman
2017-11-09 10:32:39 +00:00
parent ab43803453
commit ff911c30d6
8 changed files with 288 additions and 11 deletions

View File

@@ -0,0 +1,24 @@
from app import db
from app.models import StatsTemplateUsageByMonth
def insert_or_update_stats_for_template(template_id, month, year, count):
result = db.session.query(
StatsTemplateUsageByMonth
).filter(
StatsTemplateUsageByMonth.template_id == template_id,
StatsTemplateUsageByMonth.month == month,
StatsTemplateUsageByMonth.year == year
).update(
{
'count': count
}
)
if result == 0:
new_sms_sender = StatsTemplateUsageByMonth(
template_id=template_id,
month=month,
year=year,
count=count
)
db.session.add(new_sms_sender)