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 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_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 from . import admin
@ -14,12 +14,12 @@ import string
import random import random
from datetime import datetime, timedelta, date, time from datetime import datetime, timedelta, date, time
@admin.after_app_request #@admin.after_app_request
def after_request(response): #def after_request(response):
for query in get_recorded_queries(): # for query in get_recorded_queries():
if query.duration >= current_app.config['SLOW_DB_QUERY_TIME']: # 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)) # current_app.logger.warning('Slow query: %s\nParameters: %s\nDuration: %fs\nContext: %s\n' % (query.statement, query.parameters, query.duration, query.context))
return response # return response
@admin.route("/", methods=['GET']) @admin.route("/", methods=['GET'])
@fresh_login_required @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 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_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 . import main
from .forms import LoginForm, RegistrationForm from .forms import LoginForm, RegistrationForm
@ -10,12 +10,12 @@ from ..models import User, Permission, Item
import base64 import base64
@main.after_app_request #@main.after_app_request
def after_request(response): #def after_request(response):
for query in get_recorded_queries(): # for query in get_recorded_queries():
if query.duration >= current_app.config['SLOW_DB_QUERY_TIME']: # 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)) # current_app.logger.warning('Slow query: %s\nParameters: %s\nDuration: %fs\nContext: %s\n' % (query.statement, query.parameters, query.duration, query.context))
return response # return response
#STATIC PAGES #STATIC PAGES
@main.route("/", methods=['GET']) @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 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_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 panel
from .. import db from .. import db
@ -10,12 +10,12 @@ from ..models import User, Permission, Item
import base64 import base64
from datetime import date, time, datetime from datetime import date, time, datetime
@panel.after_app_request #@panel.after_app_request
def after_request(response): #def after_request(response):
for query in get_recorded_queries(): # for query in get_recorded_queries():
if query.duration >= current_app.config['SLOW_DB_QUERY_TIME']: # 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)) # current_app.logger.warning('Slow query: %s\nParameters: %s\nDuration: %fs\nContext: %s\n' % (query.statement, query.parameters, query.duration, query.context))
return response # return response
#@panel.route("/deploy", methods=['GET', 'POST']) #@panel.route("/deploy", methods=['GET', 'POST'])
#@login_required #@login_required