if settings.TRACK_QUERIES: count = len(request.sql_queries) sql_time = 0.0 for stmt, param, time in request.sql_queries: sql_time += time response.headers['X-SQL-Query-Count'] = str(count) response.headers['X-SQL-Query-Time'] = str(sql_time) def request_track_query(cursor, statement, parameters, time): """If there is an active request, it logs the query on it.""" if settings.TRACK_QUERIES: from solace.application import Request request = Request.current if request is not None: request.sql_queries.append((statement, parameters, time)) # make sure the session is removed at the end of the request and that # query logging for the request works. from solace.signals import after_request_shutdown, before_response_sent, \ after_cursor_executed, before_cursor_executed, before_models_committed, \ after_models_committed after_request_shutdown.connect(session.remove) before_response_sent.connect(add_query_debug_headers) after_cursor_executed.connect(request_track_query) # circular dependencies from solace import settings
"""Add headers with the SQL info.""" if settings.TRACK_QUERIES: count = len(request.sql_queries) sql_time = 0.0 for stmt, param, time in request.sql_queries: sql_time += time response.headers['X-SQL-Query-Count'] = str(count) response.headers['X-SQL-Query-Time'] = str(sql_time) def request_track_query(cursor, statement, parameters, time): """If there is an active request, it logs the query on it.""" if settings.TRACK_QUERIES: from solace.application import Request request = Request.current if request is not None: request.sql_queries.append((statement, parameters, time)) # make sure the session is removed at the end of the request and that # query logging for the request works. from solace.signals import after_request_shutdown, before_response_sent, \ after_cursor_executed, before_cursor_executed, before_models_committed, \ after_models_committed after_request_shutdown.connect(session.remove) before_response_sent.connect(add_query_debug_headers) after_cursor_executed.connect(request_track_query) # circular dependencies from solace import settings
response = e.get_response(request.environ) return finalize_response(request, response) finally: after_request_shutdown.emit() application = SharedDataMiddleware(application, { '/_static': os.path.join(os.path.dirname(__file__), 'static') }) # imported here because of possible circular dependencies from solace import settings from solace.urls import url_map from solace.i18n import select_locale, load_translations, Timezone, _, \ list_languages, has_section from solace.auth import get_auth_system from solace.database import session from solace.models import UserMessage from solace.signals import before_request_init, after_request_init, \ before_request_dispatch, after_request_dispatch, \ after_request_shutdown, before_response_sent from solace.utils.remoting import remote_export_primitive from solace.utils.csrf import get_exchange_token, is_exchange_token_protected # remember to save the session before_response_sent.connect(save_session) # important because of initialization code (such as signal subscriptions) import solace.badges
except HTTPException, e: response = e.get_response(request.environ) return finalize_response(request, response) finally: after_request_shutdown.emit() application = SharedDataMiddleware( application, {'/_static': os.path.join(os.path.dirname(__file__), 'static')}) # imported here because of possible circular dependencies from solace import settings from solace.urls import url_map from solace.i18n import select_locale, load_translations, Timezone, _, \ list_languages, has_section from solace.auth import get_auth_system from solace.database import session from solace.models import UserMessage from solace.signals import before_request_init, after_request_init, \ before_request_dispatch, after_request_dispatch, \ after_request_shutdown, before_response_sent from solace.utils.remoting import remote_export_primitive from solace.utils.csrf import get_exchange_token, is_exchange_token_protected # remember to save the session before_response_sent.connect(save_session) # important because of initialization code (such as signal subscriptions) import solace.badges