From acee9daab8a02fb4becb3a3e08202e9a6402b089 Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Wed, 22 Feb 2023 09:44:35 +0100 Subject: [PATCH] # Improves filter_show_all() * improves performance for filter_show_all() in ShareableTableFilterMixin and CheckboxCompensationTableFilter by ~40% --- compensation/filters/compensation.py | 6 ++++-- konova/filters/mixins/share.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/compensation/filters/compensation.py b/compensation/filters/compensation.py index aa1c967b..899fd132 100644 --- a/compensation/filters/compensation.py +++ b/compensation/filters/compensation.py @@ -55,10 +55,12 @@ class CheckboxCompensationTableFilter(CheckboxTableFilter): """ if not value: - return queryset.filter( + user_teams = self.user.shared_teams + result = queryset.filter( Q(intervention__users__in=[self.user]) | # requesting user has access - Q(intervention__teams__in=self.user.shared_teams) + Q(intervention__teams__in=user_teams) ).distinct() + return result else: return queryset diff --git a/konova/filters/mixins/share.py b/konova/filters/mixins/share.py index 0c94bdc9..598f75fb 100644 --- a/konova/filters/mixins/share.py +++ b/konova/filters/mixins/share.py @@ -50,9 +50,11 @@ class ShareableTableFilterMixin(django_filters.FilterSet): """ if not value: - return queryset.filter( + user_teams = self.user.shared_teams + result = queryset.filter( Q(users__in=[self.user]) | # requesting user has access - Q(teams__in=self.user.shared_teams) + Q(teams__in=user_teams) ).distinct() + return result else: return queryset \ No newline at end of file