Merge pull request #2303 from alphagov/ft-status-template-statistics

Change template statistics endpoint to use fact_notification_status_dao
This commit is contained in:
Alexey Bezhan
2019-01-17 15:04:20 +00:00
committed by GitHub
14 changed files with 112 additions and 633 deletions

View File

@@ -9,7 +9,7 @@ from notifications_utils.recipients import (
validate_and_format_phone_number,
format_email_address
)
from notifications_utils.timezones import convert_bst_to_utc, convert_utc_to_bst
from notifications_utils.timezones import convert_bst_to_utc
from app import redis_store
from app.celery import provider_tasks
@@ -33,11 +33,7 @@ from app.dao.notifications_dao import (
)
from app.v2.errors import BadRequestError
from app.utils import (
cache_key_for_service_template_counter,
cache_key_for_service_template_usage_per_day,
get_template_instance,
)
from app.utils import get_template_instance
def create_content_for_notification(template, personalisation):
@@ -126,10 +122,6 @@ def persist_notification(
if key_type != KEY_TYPE_TEST:
if redis_store.get(redis.daily_limit_cache_key(service.id)):
redis_store.incr(redis.daily_limit_cache_key(service.id))
if redis_store.get_all_from_hash(cache_key_for_service_template_counter(service.id)):
redis_store.increment_hash_value(cache_key_for_service_template_counter(service.id), template_id)
increment_template_usage_cache(service.id, template_id, notification_created_at)
current_app.logger.info(
"{} {} created at {}".format(notification_type, notification_id, notification_created_at)
@@ -137,15 +129,6 @@ def persist_notification(
return notification
def increment_template_usage_cache(service_id, template_id, created_at):
key = cache_key_for_service_template_usage_per_day(service_id, convert_utc_to_bst(created_at))
redis_store.increment_hash_value(key, template_id)
# set key to expire in eight days - we don't know if we've just created the key or not, so must assume that we
# have and reset the expiry. Eight days is longer than any notification is in the notifications table, so we'll
# always capture the full week's numbers
redis_store.expire(key, current_app.config['EXPIRE_CACHE_EIGHT_DAYS'])
def send_notification_to_queue(notification, research_mode, queue=None):
if research_mode or notification.key_type == KEY_TYPE_TEST:
queue = QueueNames.RESEARCH_MODE