From 8973e42b8602fe2dd1153bda0cfc32abc8552f40 Mon Sep 17 00:00:00 2001 From: Richard Chapman Date: Tue, 7 Nov 2017 14:50:05 +0000 Subject: [PATCH] =?UTF-8?q?Added=20a=20new=20table=20=E2=80=98stats=5Ftemp?= =?UTF-8?q?late=5Fusage=5Fby=5Fmonth=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently the 'See templates used by month' report is timing out for some services due to the query time of the data from notification_history This is a stats table which will hold the data and will be updated by a scheduled celery task once a day. This data will be combined with the 'live' data from notifications tables (which will be considerably less) to form the data of the new report. --- app/models.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/app/models.py b/app/models.py index 74b0af79a..0c64a4581 100644 --- a/app/models.py +++ b/app/models.py @@ -1555,3 +1555,37 @@ class AuthType(db.Model): __tablename__ = 'auth_type' name = db.Column(db.String, primary_key=True) + + +class StatsTemplateUsageByMonth(db.Model): + __tablename__ = "stats_template_usage_by_month" + + template_id = db.Column( + UUID(as_uuid=True), + db.ForeignKey('templates.id'), + unique=False, + index=True, + nullable=False, + primary_key=True + ) + month = db.Column( + db.Integer, + nullable=False, + index=True, + unique=False, + primary_key=True, + default=datetime.datetime.month + ) + year = db.Column( + db.Integer, + nullable=False, + index=True, + unique=False, + primary_key=True, + default=datetime.datetime.year + ) + count = db.Column( + db.Integer, + nullable=False, + default=0 + )