# Which issue(s) this PR fixes Closes https://github.com/grafana/support-escalations/issues/8143 Fix a few minor issues introduced in #3128: - Fix slow `GET /users` internal API endpoint related to [this change](https://github.com/grafana/oncall/blob/dev/engine/apps/api/views/user.py#L239) - Fix slow `GET /teams` internal API endpoint. Introduced a `short` query parameter that only invokes `apps.schedules.ical_utils.get_oncall_users_for_multiple_schedules` when `short=false`. - Order results from `GET /teams` internal API endpoint by name (ascending) - Fix search issue when searching for teams in the add responders popup window (this was strictly a frontend issue) - CSS changes to add responders dropdown to fix lonnnggg results list: **Before** <img width="377" alt="Screenshot 2023-10-31 at 10 06 20" src="https://github.com/grafana/oncall/assets/9406895/246c7c3b-7bea-44a1-afec-a38144c2c2d1"> **After** <img width="444" alt="Screenshot 2023-10-31 at 10 48 12" src="https://github.com/grafana/oncall/assets/9406895/b5602a22-c691-4dc7-bd3d-e4d6b76d04a0"> ## Still todo The `apps.schedules.ical_utils.get_oncall_users_for_multiple_schedules` method is still very slow when an instance has a lot of users (ex. `ops`). Ideally we should refactor this method to be more efficient because we still need to call this method under some circumstances. Ex. to populate this dropdown when Direct Paging a user (note that it didn't finish loading here on `ops`): <img width="1037" alt="Screenshot 2023-10-30 at 18 14 59" src="https://github.com/grafana/oncall/assets/9406895/9d91a57c-5db8-4ff9-862a-cd3755f52690"> ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required)
59 lines
1.5 KiB
Python
59 lines
1.5 KiB
Python
import typing
|
|
|
|
from rest_framework import serializers
|
|
|
|
from apps.schedules.ical_utils import SchedulesOnCallUsers
|
|
from apps.user_management.models import Team
|
|
|
|
|
|
class TeamSerializerContext(typing.TypedDict):
|
|
schedules_with_oncall_users: SchedulesOnCallUsers
|
|
|
|
|
|
class FastTeamSerializer(serializers.ModelSerializer):
|
|
id = serializers.CharField(read_only=True, source="public_primary_key")
|
|
|
|
class Meta:
|
|
model = Team
|
|
fields = ["id", "name", "email", "avatar_url"]
|
|
|
|
|
|
class TeamSerializer(serializers.ModelSerializer):
|
|
id = serializers.CharField(read_only=True, source="public_primary_key")
|
|
|
|
class Meta:
|
|
model = Team
|
|
fields = [
|
|
"id",
|
|
"name",
|
|
"email",
|
|
"avatar_url",
|
|
"is_sharing_resources_to_all",
|
|
]
|
|
|
|
read_only_fields = [
|
|
"id",
|
|
"name",
|
|
"email",
|
|
"avatar_url",
|
|
]
|
|
|
|
|
|
class TeamLongSerializer(TeamSerializer):
|
|
context: TeamSerializerContext
|
|
|
|
number_of_users_currently_oncall = serializers.SerializerMethodField()
|
|
|
|
class Meta(TeamSerializer.Meta):
|
|
fields = TeamSerializer.Meta.fields + [
|
|
"number_of_users_currently_oncall",
|
|
]
|
|
|
|
def get_number_of_users_currently_oncall(self, obj: Team) -> int:
|
|
num_of_users_oncall_for_team = 0
|
|
|
|
for schedule, users in self.context["schedules_with_oncall_users"].items():
|
|
if schedule.team == obj:
|
|
num_of_users_oncall_for_team += len(users)
|
|
|
|
return num_of_users_oncall_for_team
|