mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-06-25 18:01:57 -04:00
Only initialised service model once per request
`_get_current_service` is a function which gets called every time `current_service` is referenced in a view method or Jinja template. Because the service model was getting initialised inside this function it was being reconstructed many times in one request. On the service settings page, for example, it was getting initialised 43 times, adding about 200ms to the response time. This commit moves its initialisation to the point where we’re getting the data from the API, which only happens once per request.
This commit is contained in:
@@ -99,7 +99,7 @@ platform_stats_api_client = PlatformStatsAPIClient()
|
||||
|
||||
# The current service attached to the request stack.
|
||||
def _get_current_service():
|
||||
return Service(_lookup_req_object('service'))
|
||||
return _lookup_req_object('service')
|
||||
|
||||
|
||||
current_service = LocalProxy(_get_current_service)
|
||||
@@ -465,7 +465,9 @@ def load_service_before_request():
|
||||
|
||||
if service_id:
|
||||
try:
|
||||
_request_ctx_stack.top.service = service_api_client.get_service(service_id)['data']
|
||||
_request_ctx_stack.top.service = Service(
|
||||
service_api_client.get_service(service_id)['data']
|
||||
)
|
||||
except HTTPError as exc:
|
||||
# if service id isn't real, then 404 rather than 500ing later because we expect service to be set
|
||||
if exc.status_code == 404:
|
||||
|
||||
Reference in New Issue
Block a user