Skip to content

Commit

Permalink
In progress query optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
AaDalal committed Aug 14, 2023
1 parent 54111d2 commit b5408f7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 4 additions & 0 deletions backend/review/_optimized_queries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
qs = ReviewBit.objects.filter(
reviewbit_filters_pcr & Q(review__instructor__id=1),
review__responses__gt=0,
).values("field").annotate(avg=Avg("average", output_field=FloatField())).order_by()
11 changes: 4 additions & 7 deletions backend/review/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,20 @@ class FilledInAdvRegAvg(Subquery):
queryset = queryset.annotate(
**{
**{
(prefix + field): Subquery(
(prefix + group.field): group.avg
for group in Subquery(
ReviewBit.objects.filter(
reviewbit_subfilters,
field=field,
review__responses__gt=0,
)
.values("field")
.order_by()
.annotate(avg=Avg("average"))
.values("avg")[:1],
output_field=FloatField(),
.order_by("field")
)
for field in fields
},
**(
{
(prefix + "final_enrollment"): Subquery(
(prefix + "final_ejjknrollment"): Subquery(
ReviewBit.objects.filter(reviewbit_subfilters, review__responses__gt=0)
.values("review_id", "review__enrollment", "review__section__capacity")
.order_by()
Expand Down

0 comments on commit b5408f7

Please sign in to comment.