Optimize alertgroups endpoint (#1186)

# What this PR does

## Which issue(s) this PR fixes

## Checklist

- [ ] Tests updated
- [ ] Documentation added
- [ ] `CHANGELOG.md` updated
This commit is contained in:
Ildar Iskhakov 2023-01-21 21:59:20 +08:00 committed by GitHub
parent 5ef8b8c345
commit 83b1f069d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View file

@ -20,7 +20,7 @@ COPY ./ ./
# Collect static files and create an SQLite database
RUN mkdir -p /var/lib/oncall
RUN DJANGO_SETTINGS_MODULE=settings.prod_without_db DATABASE_TYPE=sqlite3 DATABASE_NAME=/var/lib/oncall/oncall.db SECRET_KEY="ThEmUsTSecretKEYforBUILDstage123" python manage.py collectstatic --no-input
RUN DJANGO_SETTINGS_MODULE=settings.prod_without_db DATABASE_TYPE=sqlite3 DATABASE_NAME=/var/lib/oncall/oncall.db SECRET_KEY="ThEmUsTSecretKEYforBUILDstage123" SILK_PROFILER_ENABLED="True" python manage.py collectstatic --no-input
RUN chown -R 1000:2000 /var/lib/oncall
FROM base AS dev

View file

@ -206,8 +206,14 @@ class AlertGroupView(
def get_queryset(self):
# no select_related or prefetch_related is used at this point, it will be done on paginate_queryset.
alert_receive_channels_ids = list(
AlertReceiveChannel.objects.filter(
organization_id=self.request.auth.organization.id,
team_id=self.request.user.current_team,
).values_list("id", flat=True)
)
queryset = AlertGroup.unarchived_objects.filter(
channel__organization=self.request.auth.organization, channel__team=self.request.user.current_team
channel_id__in=alert_receive_channels_ids,
).only("id")
return queryset