-
Notifications
You must be signed in to change notification settings - Fork 467
fix(Admin API): Sort features by overrides #6722
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ | |
| from common.projects.permissions import VIEW_PROJECT | ||
| from django.conf import settings | ||
| from django.core.cache import caches | ||
| from django.db.models import Max, Q, QuerySet | ||
| from django.db.models import Exists, Max, OuterRef, Q, QuerySet | ||
| from django.utils import timezone | ||
| from django.utils.decorators import method_decorator | ||
| from django.views.decorators.cache import cache_page | ||
|
|
@@ -56,7 +56,7 @@ | |
|
|
||
| from .constants import INTERSECTION, UNION | ||
| from .features_service import get_overrides_data | ||
| from .models import Feature, FeatureState | ||
| from .models import Feature, FeatureSegment, FeatureState | ||
| from .multivariate.serializers import ( | ||
| FeatureMVOptionsValuesResponseSerializer, | ||
| ) | ||
|
|
@@ -224,7 +224,29 @@ def get_queryset(self): # type: ignore[no-untyped-def] | |
| "-" if query_data["sort_direction"] == "DESC" else "", | ||
| query_data["sort_field"], | ||
| ) | ||
| queryset = queryset.order_by(sort) | ||
| override_ordering: list[str] = [] | ||
| if environment_id and (segment_id := query_data.get("segment")): | ||
| queryset = queryset.annotate( | ||
| has_segment_override=Exists( | ||
| FeatureSegment.objects.filter( | ||
| feature=OuterRef("pk"), | ||
| segment_id=segment_id, | ||
| environment_id=environment_id, | ||
| ) | ||
emyller marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ), | ||
| ) | ||
| override_ordering.append("-has_segment_override") | ||
| if identity_id := query_data.get("identity"): | ||
| queryset = queryset.annotate( | ||
| has_identity_override=Exists( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So here, this would make a subquery for each feature row right? I'm comparing to the segment query just above that have a |
||
| FeatureState.objects.filter( | ||
| feature=OuterRef("pk"), | ||
| identity_id=identity_id, | ||
| ) | ||
emyller marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ), | ||
| ) | ||
| override_ordering.append("-has_identity_override") | ||
| queryset = queryset.order_by(*override_ordering, sort) | ||
|
|
||
| if environment_id: | ||
| page = self.paginate_queryset(queryset) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,9 +88,9 @@ const UserPage: FC = () => { | |
| true, | ||
| search, | ||
| sort, | ||
| getServerFilter(filter), | ||
| { ...getServerFilter(filter), identity: id }, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we will need to use |
||
| ) | ||
| }, [filter, environmentId, projectId]) | ||
| }, [filter, environmentId, projectId, id]) | ||
|
|
||
| useEffect(() => { | ||
| AppActions.getIdentity(environmentId, id) | ||
|
|
@@ -141,10 +141,10 @@ const UserPage: FC = () => { | |
| search, | ||
| sort, | ||
| pageNumber, | ||
| getServerFilter(filter), | ||
| { ...getServerFilter(filter), identity: id }, | ||
| ) | ||
| }, | ||
| [environmentId, projectId, filter], | ||
| [environmentId, projectId, filter, id], | ||
| ) | ||
|
|
||
| return ( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes ok, that's working when identities are stored in postgres, but when using edge identities, it passes an UUID.
I'll post a full comment with my findings as we'll need to have 2 implementations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you confirm you were having integer identity.id in the screenshot you shared ?