Skip to content

Commit

Permalink
Prevent another database query during htmx requests
Browse files Browse the repository at this point in the history
  • Loading branch information
elfjes committed Dec 11, 2024
1 parent cdd8160 commit 271d34c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/argus/auth/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
See django settings for ``TEMPLATES``.
"""

import functools
from argus.auth.models import Preferences


# When ``render`` is called multiple times during a request (such as by HtmxMessageMiddleware),
# that also results in this function being called more than once for a request. That's unnecessary.
# Luckily we can cache the result for a request.
@functools.lru_cache(maxsize=10)
def preferences(request):
preferences_choices = {}
for namespace, cls in Preferences.NAMESPACES.items():
Expand Down

0 comments on commit 271d34c

Please sign in to comment.