disable slow queries

This commit is contained in:
deflax 2024-03-31 18:50:30 +03:00
parent 413176b4a0
commit 1de078d47e
3 changed files with 21 additions and 21 deletions

View file

@ -1,6 +1,6 @@
from flask import render_template, abort, redirect, url_for, abort, flash, request, current_app, make_response, g
from flask_login import fresh_login_required, login_user, logout_user
from flask_sqlalchemy import get_recorded_queries
#from flask_sqlalchemy import get_recorded_queries
from . import admin
@ -14,12 +14,12 @@ import string
import random
from datetime import datetime, timedelta, date, time
@admin.after_app_request
def after_request(response):
for query in get_recorded_queries():
if query.duration >= current_app.config['SLOW_DB_QUERY_TIME']:
current_app.logger.warning('Slow query: %s\nParameters: %s\nDuration: %fs\nContext: %s\n' % (query.statement, query.parameters, query.duration, query.context))
return response
#@admin.after_app_request
#def after_request(response):
# for query in get_recorded_queries():
# if query.duration >= current_app.config['SLOW_DB_QUERY_TIME']:
# current_app.logger.warning('Slow query: %s\nParameters: %s\nDuration: %fs\nContext: %s\n' % (query.statement, query.parameters, query.duration, query.context))
# return response
@admin.route("/", methods=['GET'])
@fresh_login_required

View file

@ -1,6 +1,6 @@
from flask import render_template, abort, redirect, url_for, abort, flash, request, current_app, make_response, g
from flask_login import login_required, login_user, logout_user, current_user
from flask_sqlalchemy import get_recorded_queries
#from flask_sqlalchemy import get_recorded_queries
from . import main
from .forms import LoginForm, RegistrationForm
@ -10,12 +10,12 @@ from ..models import User, Permission, Item
import base64
@main.after_app_request
def after_request(response):
for query in get_recorded_queries():
if query.duration >= current_app.config['SLOW_DB_QUERY_TIME']:
current_app.logger.warning('Slow query: %s\nParameters: %s\nDuration: %fs\nContext: %s\n' % (query.statement, query.parameters, query.duration, query.context))
return response
#@main.after_app_request
#def after_request(response):
# for query in get_recorded_queries():
# if query.duration >= current_app.config['SLOW_DB_QUERY_TIME']:
# current_app.logger.warning('Slow query: %s\nParameters: %s\nDuration: %fs\nContext: %s\n' % (query.statement, query.parameters, query.duration, query.context))
# return response
#STATIC PAGES
@main.route("/", methods=['GET'])

View file

@ -1,6 +1,6 @@
flask import render_template, abort, redirect, url_for, abort, flash, request, current_app, make_response, g
from flask_login import login_required, login_user, logout_user, current_user
from flask_sqlalchemy import get_recorded_queries
#from flask_sqlalchemy import get_recorded_queries
from . import panel
from .. import db
@ -10,12 +10,12 @@ from ..models import User, Permission, Item
import base64
from datetime import date, time, datetime
@panel.after_app_request
def after_request(response):
for query in get_recorded_queries():
if query.duration >= current_app.config['SLOW_DB_QUERY_TIME']:
current_app.logger.warning('Slow query: %s\nParameters: %s\nDuration: %fs\nContext: %s\n' % (query.statement, query.parameters, query.duration, query.context))
return response
#@panel.after_app_request
#def after_request(response):
# for query in get_recorded_queries():
# if query.duration >= current_app.config['SLOW_DB_QUERY_TIME']:
# current_app.logger.warning('Slow query: %s\nParameters: %s\nDuration: %fs\nContext: %s\n' % (query.statement, query.parameters, query.duration, query.context))
# return response
#@panel.route("/deploy", methods=['GET', 'POST'])
#@login_required