Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable user_loading on arbitrary endpoints #439

Closed
lukasjuhrich opened this issue Jun 2, 2022 · 2 comments
Closed

Disable user_loading on arbitrary endpoints #439

lukasjuhrich opened this issue Jun 2, 2022 · 2 comments
Assignees

Comments

@lukasjuhrich
Copy link
Collaborator

To be dealt with after #370.

For some reason, loading an asset while being logged in (i.e., being handled by the static endpoint) triggers the user loader, causing a lot of API calls – but there should be None, we don't need any information about the user when serving, say, a .css file.

There should be a (regression) test for this, as this has a significant performance impact.

@lukasjuhrich
Copy link
Collaborator Author

A comparison: https://agdsn.de/sipa/news
logged in:
image
logged out:
image

@lukasjuhrich
Copy link
Collaborator Author

What triggers the user loader on /static endpoints is the use of current_user in the log method:

Traceback (most recent call last):
  File "/home/lukas/.virtualenvs/sipa/lib/python3.10/site-packages/flask/app.py", line 2095, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/lukas/.virtualenvs/sipa/lib/python3.10/site-packages/werkzeug/middleware/proxy_fix.py", line 187, in __call__
    return self.app(environ, start_response)
  File "/home/lukas/.virtualenvs/sipa/lib/python3.10/site-packages/flask/app.py", line 2080, in wsgi_app
    response = self.handle_exception(e)
  File "/home/lukas/.virtualenvs/sipa/lib/python3.10/site-packages/flask/app.py", line 2077, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/lukas/.virtualenvs/sipa/lib/python3.10/site-packages/flask/app.py", line 1525, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/lukas/.virtualenvs/sipa/lib/python3.10/site-packages/flask/app.py", line 1521, in full_dispatch_request
    rv = self.preprocess_request()
  File "/home/lukas/.virtualenvs/sipa/lib/python3.10/site-packages/flask/app.py", line 1861, in preprocess_request
    rv = self.ensure_sync(before_func)()
  File "/home/lukas/code/10ag/sipa/sipa/blueprints/generic.py", line 34, in log_request
    extra={'tags': {'user': get_user_name(current_user),
  File "/home/lukas/code/10ag/sipa/sipa/utils/__init__.py", line 112, in get_user_name
    if user.is_authenticated:
  File "/home/lukas/.virtualenvs/sipa/lib/python3.10/site-packages/werkzeug/local.py", line 436, in __get__
    obj = instance._get_current_object()
  File "/home/lukas/.virtualenvs/sipa/lib/python3.10/site-packages/werkzeug/local.py", line 565, in _get_current_object
    return self.__local()  # type: ignore
  File "/home/lukas/.virtualenvs/sipa/lib/python3.10/site-packages/flask_login/utils.py", line 26, in <lambda>
    current_user = LocalProxy(lambda: _get_user())
  File "/home/lukas/.virtualenvs/sipa/lib/python3.10/site-packages/flask_login/utils.py", line 384, in _get_user
    current_app.login_manager._load_user()
  File "/home/lukas/.virtualenvs/sipa/lib/python3.10/site-packages/flask_login/login_manager.py", line 355, in _load_user
    user = self._user_callback(user_id)
  File "/home/lukas/code/10ag/sipa/sipa/base.py", line 38, in load_user
    raise RuntimeError
RuntimeError

(I artificially injected the RuntimeError to get a stacktrace)

@lukasjuhrich lukasjuhrich self-assigned this Jun 6, 2022
@lukasjuhrich lukasjuhrich changed the title Disable user_loading on endpoints Disable user_loading on arbitrary endpoints Jun 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant