mirror of
https://github.com/GSA/notifications-api.git
synced 2026-05-27 09:28:03 -04:00
Commit transactions as soon no longer needed
We think that holding open database transactions while we go and do something else is causing us to have poor performance. Because we’re not serialising everything as soon as we pull it out of the database we can guarantee that we don’t need to go back to the database again. So let’s see if explicitly closing the transaction helps with performance.
This commit is contained in:
@@ -8,6 +8,7 @@ from sqlalchemy.exc import DataError
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
from gds_metrics import Histogram
|
||||
|
||||
from app import db
|
||||
from app.dao.services_dao import dao_fetch_service_by_id
|
||||
from app.dao.api_key_dao import get_model_api_keys
|
||||
from app.serialised_models import (
|
||||
@@ -123,6 +124,7 @@ def requires_auth():
|
||||
try:
|
||||
service = get_service_model(issuer)
|
||||
service.api_keys = get_api_keys_models(issuer)
|
||||
db.session.commit()
|
||||
except DataError:
|
||||
raise AuthError("Invalid token: service id is not the right data type", 403)
|
||||
except NoResultFound:
|
||||
|
||||
@@ -8,6 +8,7 @@ from notifications_utils.recipients import (
|
||||
)
|
||||
from notifications_utils.clients.redis import rate_limit_cache_key, daily_limit_cache_key
|
||||
|
||||
from app import db
|
||||
from app.dao import services_dao, templates_dao
|
||||
from app.dao.service_sms_sender_dao import dao_get_service_sms_senders_by_id
|
||||
from app.models import (
|
||||
@@ -160,7 +161,10 @@ def get_template_dict(template_id, service_id):
|
||||
raise BadRequestError(message=message,
|
||||
fields=[{'template': message}])
|
||||
|
||||
return template_schema.dump(fetched_template).data
|
||||
template_dict = template_schema.dump(fetched_template).data
|
||||
|
||||
db.session.commit()
|
||||
return template_dict
|
||||
|
||||
|
||||
def get_template_model(template_id, service_id):
|
||||
|
||||
Reference in New Issue
Block a user