slight refactors

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens Langhammer
2025-06-08 20:44:55 +02:00
parent fde6120e67
commit 6e1cf8a23c
2 changed files with 15 additions and 18 deletions

View File

@ -153,10 +153,10 @@ class ApplicationViewSet(UsedByMixin, ModelViewSet):
return applications return applications
def _filter_applications_with_launch_url( def _filter_applications_with_launch_url(
self, pagined_apps: Iterator[Application] self, paginated_apps: Iterator[Application]
) -> list[Application]: ) -> list[Application]:
applications = [] applications = []
for app in pagined_apps: for app in paginated_apps:
if app.get_launch_url(): if app.get_launch_url():
applications.append(app) applications.append(app)
return applications return applications

View File

@ -3,7 +3,6 @@
from collections.abc import Iterable from collections.abc import Iterable
from multiprocessing import Pipe, current_process from multiprocessing import Pipe, current_process
from multiprocessing.connection import Connection from multiprocessing.connection import Connection
from time import perf_counter
from django.core.cache import cache from django.core.cache import cache
from django.db.models import Count, Q, QuerySet from django.db.models import Count, Q, QuerySet
@ -82,10 +81,17 @@ class PolicyEngine:
def _check_cache(self, binding: PolicyBinding): def _check_cache(self, binding: PolicyBinding):
if not self.use_cache: if not self.use_cache:
return False return False
before = perf_counter() # It's a bit silly to time this, but
with HIST_POLICIES_EXECUTION_TIME.labels(
binding_order=binding.order,
binding_target_type=binding.target_type,
binding_target_name=binding.target_name,
object_pk=str(self.request.obj.pk),
object_type=class_to_path(self.request.obj.__class__),
mode="cache_retrieve",
).time():
key = cache_key(binding, self.request) key = cache_key(binding, self.request)
cached_policy = cache.get(key, None) cached_policy = cache.get(key, None)
duration = max(perf_counter() - before, 0)
if not cached_policy: if not cached_policy:
return False return False
self.logger.debug( self.logger.debug(
@ -94,15 +100,6 @@ class PolicyEngine:
cache_key=key, cache_key=key,
request=self.request, request=self.request,
) )
HIST_POLICIES_EXECUTION_TIME.labels(
binding_order=binding.order,
binding_target_type=binding.target_type,
binding_target_name=binding.target_name,
object_pk=str(self.request.obj.pk),
object_type=class_to_path(self.request.obj.__class__),
mode="cache_retrieve",
).observe(duration)
# It's a bit silly to time this, but
self.__cached_policies.append(cached_policy) self.__cached_policies.append(cached_policy)
return True return True