flask-security
flask-security copied to clipboard
too many query into User/Role table
I am seeing more than 10 queries into User/Role tables for my average web page, which displays a few charts. Is this normal? It unnecessarily increase database traffic, and clutters the flask app log.
I have seen similar issues raised, but not directly with this project here: http://stackoverflow.com/questions/23069644/flask-sqlalchemy-one-get-many-db-queries https://gist.github.com/nickretallack/7830268
The second case involves Flask-Admin, which I am also using.
Wondering if there's anyway to reduce the number of quries into User/Role table.
@threemonks I'm not sure what the issue is here. If you share the code for your views, I may be able to help.
Based on the comments in your StackOverflow question, it looks like you've dropped Flask-Security for this, so I'm closing this issue. If that's not the case, and you would still like help addressing this issue, feel free to reopen it.
That StackOverflow question is not mine.
From what I can see, it does multiple (>=6) queries into User/Role tables regardless of which view I visit. For example, a simple view that display an html template with no database operation other than displaying welcome message to user, like this:
@app.route('/')
@app.route("/sitemap/")
def sitemap():
`return render_template('sitemap.html')``
The relevant code piece in template that display a welcome message is like this:
{% if current_user.is_authenticated %}
Hi {{ current_user.username }} |
<a href="{{ url_for('security.logout') }}">Logout</a>
{% else %}
<a href="{{ url_for('security.login') }}">Login</a>
{% endif %}
Note that I do have a app.before_request to require login for every page, as I want my site to be protected over internet connection.
@app.before_request
def default_login_required():
# exclude 404 errors and static routes
if not request.endpoint or current_user.is_authenticated or request.endpoint.rsplit('.', 1)[-1] == 'static' or request.endpoint == "login" or request.endpoint == "security.login":
return
return redirect(url_for('security.login', next=request.script_root + request.path))
Thanks
Updated my previous comment with the app.before_request detail, which is probably related. But I would not expect so many database queries even with app.before_request to mandate login for every page.
Were there any update on this issue?