mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 18:01:08 -05:00
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:
24
app/dao/stats_template_usage_by_month_dao.py
Normal file
24
app/dao/stats_template_usage_by_month_dao.py
Normal 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)
|
||||
Reference in New Issue
Block a user