Skip to content

Commit

Permalink
Switch to live objects manager
Browse files Browse the repository at this point in the history
  • Loading branch information
zachaysan committed Aug 8, 2024
1 parent aa7c771 commit 8569c85
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/environments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def get_segments_from_cache(self) -> typing.List[Segment]:
segments = environment_segments_cache.get(self.id)
if not segments:
segments = list(
Segment.objects.filter(
Segment.live_objects.filter(
feature_segments__feature_states__environment=self
).prefetch_related(
"rules",
Expand Down
5 changes: 4 additions & 1 deletion api/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,22 @@ def edge_v2_identity_overrides_migrated(self) -> bool:
return self.edge_v2_migration_status == EdgeV2MigrationStatus.COMPLETE

def get_segments_from_cache(self):
from segments.models import Segment

segments = project_segments_cache.get(self.id)

if not segments:
# This is optimised to account for rules nested one levels deep (since we
# don't support anything above that from the UI at the moment). Anything
# past that will require additional queries / thought on how to optimise.
segments = self.segments.all().prefetch_related(
segments = Segment.live_objects.filter(project=self).prefetch_related(
"rules",
"rules__conditions",
"rules__rules",
"rules__rules__conditions",
"rules__rules__rules",
)

project_segments_cache.set(
self.id, segments, timeout=settings.CACHE_PROJECT_SEGMENTS_SECONDS
)
Expand Down
2 changes: 1 addition & 1 deletion api/segments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_queryset(self):
)
project = get_object_or_404(permitted_projects, pk=self.kwargs["project_pk"])

queryset = project.segments.all()
queryset = Segment.live_objects.filter(project=project)

if self.action == "list":
# TODO: at the moment, the UI only shows the name and description of the segment in the list view.
Expand Down

0 comments on commit 8569c85

Please sign in to comment.