mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 07:21:13 -05:00
Return count of notifications in the database for a job
When we cancel a job, we need to check if all notifications are already in the database. So far, we were querying for all notification objects in the database and counting them in admin app, which runs into pagination problems for large jobs, and could time out for very large jobs.
This commit is contained in:
@@ -20,7 +20,7 @@ from app.dao.jobs_dao import (
|
||||
from app.dao.fact_notification_status_dao import fetch_notification_statuses_for_job
|
||||
from app.dao.services_dao import dao_fetch_service_by_id
|
||||
from app.dao.templates_dao import dao_get_template_by_id
|
||||
from app.dao.notifications_dao import get_notifications_for_job
|
||||
from app.dao.notifications_dao import dao_get_notification_count_for_job_id, get_notifications_for_job
|
||||
from app.schemas import (
|
||||
job_schema,
|
||||
unarchived_template_schema,
|
||||
@@ -108,6 +108,14 @@ def get_all_notifications_for_service_job(service_id, job_id):
|
||||
), 200
|
||||
|
||||
|
||||
@job_blueprint.route('/<job_id>/notification_count', methods=['GET'])
|
||||
def get_notification_count_for_job_id(service_id, job_id):
|
||||
count = dao_get_notification_count_for_job_id(job_id)
|
||||
return jsonify(
|
||||
count=count
|
||||
), 200
|
||||
|
||||
|
||||
@job_blueprint.route('', methods=['GET'])
|
||||
def get_jobs_by_service(service_id):
|
||||
if request.args.get('limit_days'):
|
||||
|
||||
Reference in New Issue
Block a user