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:
Chris Hill-Scott
2020-06-17 14:09:39 +01:00
parent 4a3dc26fbf
commit 34d5054075
2 changed files with 7 additions and 1 deletions

View File

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

View File

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