mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 23:55:58 -05:00
Removed/replaced retention redis count with notification count from db call
This commit is contained in:
committed by
Carlo Costino
parent
246e23f193
commit
a346a734fc
@@ -2,7 +2,6 @@ import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from flask import current_app
|
||||
from notifications_utils.clients import redis
|
||||
from notifications_utils.recipients import (
|
||||
format_email_address,
|
||||
get_international_phone_info,
|
||||
@@ -10,7 +9,6 @@ from notifications_utils.recipients import (
|
||||
)
|
||||
from notifications_utils.template import PlainTextEmailTemplate, SMSMessageTemplate
|
||||
|
||||
from app import redis_store
|
||||
from app.celery import provider_tasks
|
||||
from app.config import QueueNames
|
||||
from app.dao.notifications_dao import (
|
||||
@@ -141,17 +139,7 @@ def persist_notification(
|
||||
service.id
|
||||
)
|
||||
)
|
||||
total_key = redis.daily_total_cache_key()
|
||||
if redis_store.get(total_key) is None:
|
||||
current_app.logger.info("Redis daily total cache key does not exist")
|
||||
redis_store.set(total_key, 1, ex=86400)
|
||||
current_app.logger.info("Set redis daily total cache key to 1")
|
||||
else:
|
||||
current_app.logger.info("Redis total limit cache key does exist")
|
||||
redis_store.incr(total_key)
|
||||
current_app.logger.info(
|
||||
f"Redis total limit cache key has been incremented to {redis_store.get(total_key)}"
|
||||
)
|
||||
|
||||
current_app.logger.info(
|
||||
"{} {} created at {}".format(
|
||||
notification_type, notification_id, notification_created_at
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from flask import current_app
|
||||
from notifications_utils import SMS_CHAR_COUNT_LIMIT
|
||||
from notifications_utils.clients.redis import (
|
||||
daily_total_cache_key,
|
||||
rate_limit_cache_key,
|
||||
total_limit_cache_key,
|
||||
)
|
||||
@@ -13,6 +12,7 @@ from notifications_utils.recipients import (
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
from app import redis_store
|
||||
from app.dao.notifications_dao import dao_get_notification_count_for_service
|
||||
from app.dao.service_email_reply_to_dao import dao_get_reply_to_by_id
|
||||
from app.dao.service_sms_sender_dao import dao_get_service_sms_senders_by_id
|
||||
from app.models import (
|
||||
@@ -69,15 +69,10 @@ def check_service_over_total_message_limit(key_type, service):
|
||||
def check_application_over_retention_limit(key_type, service):
|
||||
if key_type == KEY_TYPE_TEST or not current_app.config["REDIS_ENABLED"]:
|
||||
return 0
|
||||
total_stats = dao_get_notification_count_for_service(service=service)
|
||||
|
||||
cache_key = daily_total_cache_key()
|
||||
daily_message_limit = current_app.config["DAILY_MESSAGE_LIMIT"]
|
||||
total_stats = redis_store.get(cache_key)
|
||||
if total_stats is None:
|
||||
# first message of the day, set the cache to 0 and the expiry to 24 hours
|
||||
total_stats = 0
|
||||
redis_store.set(cache_key, total_stats, ex=86400)
|
||||
return total_stats
|
||||
|
||||
if int(total_stats) >= daily_message_limit:
|
||||
current_app.logger.info(
|
||||
"while sending for service {}, daily message limit of {} reached".format(
|
||||
|
||||
Reference in New Issue
Block a user