Skip to content

Conversation

@stsewd
Copy link
Member

@stsewd stsewd commented Aug 6, 2025

This used to be 35 queries. I found another optimization to make it to constant time, but will open another PR as it may produce a slow query..

@stsewd stsewd marked this pull request as ready for review August 6, 2025 18:07
@stsewd stsewd requested a review from a team as a code owner August 6, 2025 18:07
@stsewd stsewd requested a review from ericholscher August 6, 2025 18:07
Build.internal.filter(project=OuterRef("project_id"))
.order_by("-date")
.values_list("id", flat=True)[:1]
Build.internal.filter(project=OuterRef("project_id")).order_by("-date").values("pk")[:1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this make it faster, or just cleaner?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just cleaner, looks like django was able to get to the same SQL

@stsewd stsewd merged commit 90d1cf8 into main Aug 7, 2025
5 checks passed
@stsewd stsewd deleted the optimize-dashboard branch August 7, 2025 15:45
stsewd added a commit that referenced this pull request Aug 11, 2025
…12385)

This is on top of
#12383 as another PR
in case we see a regression in performance, it would be easier to just
revert this change.

Instead of pre-fetching, we annotate, so we can use exist instead of
fetching the query. This allows to just make one query. But this does
add some extra complexity to the query itself, which is less overhead
than doing a prefetch over the queryset itself, but the pagination
package we are using calls .count(), and django includes the annotation
by default... which makes that query slower as well... but testing in
production shows faster results still.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants