From 26aa155b9e3696973de7e0fb75c957bee86a6a46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 12 Oct 2016 14:29:47 +0200 Subject: [PATCH] Cache Pillar API Object on request object. --- pillar/web/system_util.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pillar/web/system_util.py b/pillar/web/system_util.py index 1bc3e0ca..ebc27384 100644 --- a/pillar/web/system_util.py +++ b/pillar/web/system_util.py @@ -4,7 +4,7 @@ Replacement of the old SystemUtility class. import os import logging -from flask import current_app, session +from flask import current_app, session, request from flask_login import current_user from pillar.sdk import FlaskInternalApi @@ -35,6 +35,11 @@ def pillar_server_endpoint_static(): def pillar_api(token=None): + # Cache API objects on the request. + api = getattr(request, 'pillar_api', None) + if api is not None: + return api + # Check if current_user is initialized (in order to support manage.py # scripts and non authenticated server requests). if token is None and current_user and current_user.is_authenticated: @@ -47,6 +52,7 @@ def pillar_api(token=None): token=token ) + request.pillar_api = api return api