Skip to content

Commit

Permalink
perf(projects): use unusedFeatures in more places (#82065)
Browse files Browse the repository at this point in the history
use the `ununusedFeatures` collapse parameter in more places. see some
slowness due to teams serializer having to render all of the project
feature flags.
  • Loading branch information
JoshFerge authored Dec 13, 2024
1 parent d167211 commit 3d51b11
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/sentry/api/endpoints/project_team_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ def post(self, request: Request, project, team: Team) -> Response:
event=audit_log.get_event_id("PROJECT_TEAM_ADD"),
data={"team_slug": team.slug, "project_slug": project.slug},
)
return Response(serialize(project, request.user, ProjectWithTeamSerializer()), status=201)
return Response(
serialize(
project, request.user, ProjectWithTeamSerializer(collapse=["unusedFeatures"])
),
status=201,
)

@extend_schema(
operation_id="Delete a Team from a Project",
Expand Down
8 changes: 7 additions & 1 deletion src/sentry/api/serializers/models/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ def _collapse(self, key: str) -> bool:
def get_attrs(
self, item_list: Sequence[Team], user: User, **kwargs: Any
) -> dict[Team, dict[str, Any]]:
from sentry.api.serializers.models.project import ProjectSerializer

request = env.request
org_ids = {t.organization_id for t in item_list}

Expand Down Expand Up @@ -244,7 +246,11 @@ def get_attrs(
projects = [pt.project for pt in project_teams]

projects_by_id = {
project.id: data for project, data in zip(projects, serialize(projects, user))
project.id: data
for project, data in zip(
projects,
serialize(projects, user, ProjectSerializer(collapse=["unusedFeatures"])),
)
}

project_map = defaultdict(list)
Expand Down
5 changes: 4 additions & 1 deletion tests/sentry/api/serializers/test_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.conf import settings

from sentry.api.serializers import serialize
from sentry.api.serializers.models.project import ProjectSerializer
from sentry.api.serializers.models.team import TeamSCIMSerializer, TeamWithProjectsSerializer
from sentry.app import env
from sentry.models.organizationmember import InviteStatus
Expand Down Expand Up @@ -252,7 +253,9 @@ def test_simple(self):
project2 = self.create_project(teams=[team], organization=organization, name="bar")

result = serialize(team, user, TeamWithProjectsSerializer())
serialized_projects = serialize([project2, project], user)
serialized_projects = serialize(
[project2, project], user, ProjectSerializer(collapse=["unusedFeatures"])
)

assert result == {
"id": str(team.id),
Expand Down

0 comments on commit 3d51b11

Please sign in to comment.