Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions api/features/feature_lifecycle/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from django.db.models.expressions import Case, Exists, OuterRef, Value, When
from django.db.models.fields import BooleanField
from django.db.models.functions import Cast
from django.db.models.query import QuerySet
from django.utils import timezone

Expand Down Expand Up @@ -42,7 +41,7 @@ def annotate_feature_queryset_with_lifecycle_stage(
has_recent_usage=(
Exists(features_in_use.filter(pk=OuterRef("pk")))
if features_in_use is not None
else Cast(Value(None), output_field=BooleanField())
else Value(None, output_field=BooleanField())
),
has_permanent_tag=Exists(
Tag.objects.filter(feature=OuterRef("pk"), is_permanent=True),
Expand Down
11 changes: 6 additions & 5 deletions api/features/feature_lifecycle/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections import Counter

import structlog
from common.environments.permissions import VIEW_ENVIRONMENT
from django.db.models import Count
from django.shortcuts import get_object_or_404
from drf_spectacular.utils import extend_schema
from rest_framework.permissions import IsAuthenticated
Expand Down Expand Up @@ -44,10 +45,10 @@ def get(self, request: Request, environment_pk: int) -> Response:
environment,
)

counts = features.values("lifecycle_stage").annotate(count=Count("pk")) # type: ignore[misc]
summary: dict[LifecycleStage, int] = {stage: 0 for stage in LifecycleStage}
for stage_count in counts:
summary[stage_count["lifecycle_stage"]] = stage_count["count"]
counts = Counter(features.values_list("lifecycle_stage", flat=True)) # type: ignore[misc]
summary: dict[LifecycleStage, int] = {
stage: counts.get(stage, 0) for stage in LifecycleStage
}
Comment on lines -47 to +51

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Judging by the amount of features I can see in SaaS, this doesn't add much. Though I'd be really surprised if Oracle can't do count + group by together. 🤔 Did you see a specific error?


logger.info(
"summarised",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Attributes:
### `feature_lifecycle.summarised`

Logged at `info` from:
- `api/features/feature_lifecycle/views.py:52`
- `api/features/feature_lifecycle/views.py:53`

Attributes:
- `environment.id`
Expand Down
Loading