Added a new table ‘stats_template_usage_by_month’

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.
This commit is contained in:
Richard Chapman
2017-11-07 14:50:05 +00:00
parent a77c316d2f
commit 8973e42b86

View File

@@ -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
)