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
15 changes: 1 addition & 14 deletions src/sentry/api/serializers/models/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,6 @@ def get_filters(self, obj: Dashboard) -> tuple[PageFilters, DashboardFilters]:

class DashboardListSerializer(Serializer, DashboardFiltersMixin):
def get_attrs(self, item_list, user, **kwargs):
organization = kwargs.get("context", {}).get("organization")
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.

Unnecessary prefetch of removed feature's data

Low Severity

The prefetch_related_objects call still includes "dashboardlastvisited_set__member", but the only code that consumed this prefetched data (the per-user last_visited lookup inside the feature flag check) was removed in this same PR. This causes unnecessary database queries—joining DashboardLastVisited and OrganizationMember—on every dashboard list request, with no code ever reading the results.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 2a18f5d. Configure here.

item_dict = {i.id: i for i in item_list}
prefetch_related_objects(
item_list, "projects__organization", "dashboardlastvisited_set__member"
Expand Down Expand Up @@ -582,19 +581,7 @@ def get_attrs(self, item_list, user, **kwargs):
result[dashboard]["permissions"] = serialize(permission)

for dashboard in item_dict.values():
if features.has(
"organizations:dashboards-starred-reordering",
organization,
actor=user,
):
visit = dashboard.dashboardlastvisited_set.filter(
dashboard=dashboard,
member__user_id=user.id,
member__organization=organization,
).first()
result[dashboard]["last_visited"] = visit.last_visited if visit else None
else:
result[dashboard]["last_visited"] = dashboard.last_visited
result[dashboard]["last_visited"] = dashboard.last_visited

result[dashboard]["created_by"] = serialized_users.get(str(dashboard.created_by_id))
result[dashboard]["is_favorited"] = dashboard.id in favorited_dashboard_ids
Expand Down
14 changes: 0 additions & 14 deletions src/sentry/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,6 @@
OrganizationDashboardWidgetDetailsEndpoint,
)
from sentry.dashboards.endpoints.organization_dashboards import OrganizationDashboardsEndpoint
from sentry.dashboards.endpoints.organization_dashboards_starred import (
OrganizationDashboardsStarredEndpoint,
OrganizationDashboardsStarredOrderEndpoint,
)
from sentry.data_export.endpoints.data_export import DataExportEndpoint
from sentry.data_export.endpoints.data_export_details import DataExportDetailsEndpoint
from sentry.data_secrecy.api.waive_data_secrecy import WaiveDataSecrecyEndpoint
Expand Down Expand Up @@ -1593,16 +1589,6 @@ def create_group_urls(name_prefix: str) -> list[URLPattern | URLResolver]:
OrganizationDashboardWidgetDetailsEndpoint.as_view(),
name="sentry-api-0-organization-dashboard-widget-details",
),
re_path(
r"^(?P<organization_id_or_slug>[^/]+)/dashboards/starred/$",
OrganizationDashboardsStarredEndpoint.as_view(),
name="sentry-api-0-organization-dashboard-starred",
),
re_path(
r"^(?P<organization_id_or_slug>[^/]+)/dashboards/starred/order/$",
OrganizationDashboardsStarredOrderEndpoint.as_view(),
name="sentry-api-0-organization-dashboard-starred-order",
),
re_path(
r"^(?P<organization_id_or_slug>[^/]+)/dashboards/generate/$",
OrganizationDashboardGenerateEndpoint.as_view(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from sentry.dashboards.endpoints.organization_dashboards import OrganizationDashboardsPermission
from sentry.models.dashboard import (
Dashboard,
DashboardFavoriteUser,
DashboardLastVisited,
DashboardRevision,
)
Expand Down Expand Up @@ -280,23 +279,6 @@ def put(self, request: Request, organization: Organization, dashboard: Dashboard

is_favorited = request.data.get("isFavorited")

if features.has(
"organizations:dashboards-starred-reordering", organization, actor=request.user
):
if is_favorited:
DashboardFavoriteUser.objects.insert_favorite_dashboard(
organization=organization,
user_id=request.user.id,
dashboard=dashboard,
)
else:
DashboardFavoriteUser.objects.unfavorite_dashboard(
organization=organization,
user_id=request.user.id,
dashboard=dashboard,
)
return Response(status=204)

current_favorites = set(dashboard.favorited_by)

if is_favorited and request.user.id not in current_favorites:
Expand Down
59 changes: 2 additions & 57 deletions src/sentry/dashboards/endpoints/organization_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@
from django.db import IntegrityError, router, transaction
from django.db.models import (
Case,
Count,
Exists,
F,
IntegerField,
OrderBy,
OuterRef,
Q,
Subquery,
Value,
When,
)
Expand Down Expand Up @@ -49,7 +45,7 @@
from sentry.auth.superuser import is_active_superuser
from sentry.db.models.fields.text import CharField
from sentry.locks import locks
from sentry.models.dashboard import Dashboard, DashboardFavoriteUser, DashboardLastVisited
from sentry.models.dashboard import Dashboard, DashboardFavoriteUser
from sentry.models.organization import Organization
from sentry.organizations.services.organization.model import (
RpcOrganization,
Expand Down Expand Up @@ -463,28 +459,7 @@ def get(self, request: Request, organization: Organization) -> Response:
]

elif sort_by == "recentlyViewed":
if features.has(
"organizations:dashboards-starred-reordering", organization, actor=request.user
):
dashboards = dashboards.annotate(
user_last_visited=Subquery(
DashboardLastVisited.objects.filter(
dashboard=OuterRef("pk"),
member__user_id=request.user.id,
member__organization=organization,
).values("last_visited")
)
)
order_by = [
(
F("user_last_visited").asc(nulls_last=True)
if desc
else F("user_last_visited").desc(nulls_last=True)
),
"-date_added",
]
else:
order_by = ["last_visited" if desc else "-last_visited"]
order_by = ["last_visited" if desc else "-last_visited"]

elif sort_by == "mydashboards":
user_name_dict = {
Expand Down Expand Up @@ -525,21 +500,6 @@ def get(self, request: Request, organization: Organization) -> Response:
"-last_visited",
]

elif sort_by == "mostFavorited" and features.has(
"organizations:dashboards-starred-reordering", organization, actor=request.user
):
dashboards = dashboards.annotate(
favorites_count=Count(
"dashboardfavoriteuser",
filter=Q(dashboardfavoriteuser__favorited=True),
distinct=True,
)
)
order_by = [
"favorites_count" if desc else "-favorites_count",
"-date_added",
]

else:
order_by = ["title"]

Expand Down Expand Up @@ -641,21 +601,6 @@ def post(self, request: Request, organization: Organization, retry: int = 0) ->

dashboard = serializer.save()

if features.has(
"organizations:dashboards-starred-reordering",
organization,
actor=request.user,
):
if serializer.validated_data.get("is_favorited"):
try:
DashboardFavoriteUser.objects.insert_favorite_dashboard(
organization=organization,
user_id=request.user.id,
dashboard=dashboard,
)
except Exception as e:
sentry_sdk.capture_exception(e)

return Response(serialize(dashboard, request.user), status=201)
except IntegrityError:
if retry >= MAX_RETRIES:
Expand Down
113 changes: 0 additions & 113 deletions src/sentry/dashboards/endpoints/organization_dashboards_starred.py

This file was deleted.

2 changes: 0 additions & 2 deletions src/sentry/features/temporary.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ def register_temporary_features(manager: FeatureManager) -> None:
manager.add("organizations:dashboards-import", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=True)
# Enable metrics enhanced performance for AM2+ customers as they transition from AM2 to AM3
manager.add("organizations:dashboards-metrics-transition", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=True)
# Enable starred dashboards with reordering
manager.add("organizations:dashboards-starred-reordering", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=True)
# Enable drilldown flow for dashboards
manager.add("organizations:dashboards-drilldown-flow", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=True)
# Enable prebuilt dashboards for insights modules
Expand Down
2 changes: 0 additions & 2 deletions static/app/utils/api/knownSentryApiUrls.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ export type KnownSentryApiUrls =
| '/organizations/$organizationIdOrSlug/dashboards/$dashboardId/revisions/$revisionId/restore/'
| '/organizations/$organizationIdOrSlug/dashboards/$dashboardId/visit/'
| '/organizations/$organizationIdOrSlug/dashboards/generate/'
| '/organizations/$organizationIdOrSlug/dashboards/starred/'
| '/organizations/$organizationIdOrSlug/dashboards/starred/order/'
| '/organizations/$organizationIdOrSlug/dashboards/widgets/'
| '/organizations/$organizationIdOrSlug/data-conditions/'
| '/organizations/$organizationIdOrSlug/data-export/'
Expand Down
Loading
Loading