Skip to content

Improve crates endpoint performance #7941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 19, 2024
Merged

Conversation

eth3lbert
Copy link
Contributor

@eth3lbert eth3lbert commented Jan 15, 2024

This pr improve the performance by utilizing a count subquery for total retrieval.

P.S. make a separate query to fetch total should also outperforms window functions in this context.

Enable consistent filtering for both data retrieval and count queries,
and ensure accurate totals in seek-based pagination.
@Turbo87 Turbo87 added C-enhancement ✨ Category: Adding new behavior or a change to the way an existing feature works A-backend ⚙️ labels Jan 15, 2024
@Turbo87 Turbo87 requested a review from LawnGnome January 15, 2024 10:26
Copy link

codecov bot commented Jan 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (main@c6c0a16). Click here to learn what that means.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7941   +/-   ##
=======================================
  Coverage        ?   87.57%           
=======================================
  Files           ?      257           
  Lines           ?    25101           
  Branches        ?        0           
=======================================
  Hits            ?    21982           
  Misses          ?     3119           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@LawnGnome LawnGnome left a comment

Choose a reason for hiding this comment

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

I like this! I particularly like the new test assertions.

I experimented with a similar change last year, but trying to fully automatically build the count query instead of having it added separately. Turned out to be really hard (maybe actually impossible, right now?) because of what Diesel does and doesn't expose from its innards. So I like this as a pragmatic middle ground, and I like that the changes to the controller weren't as bad as I thought they'd be last year.

@Turbo87 Let's give this a quick once over on staging before we deploy, but I think this is good.

}

fn supports_seek(&self) -> bool {
// Calculating the total number of results with filters is supported but paging is not supported yet.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm correct in thinking this isn't a regression, right, because we don't support this today?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, and I also like to make a follow up PR which expands the scope of the seek-based pagination for crates endpoint.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For offset-based pagination, the response will remain unchanged. The only modification pertains to seek-based pagination. Previously, we provided an approximate total count; however, with this PR, the total count will align precisely with the offset-based count.

@Turbo87
Copy link
Member

Turbo87 commented Jan 19, 2024

Let's give this a quick once over on staging before we deploy, but I think this is good.

I've just deployed main to production, so we can now merge this and test it out on staging.

thanks a lot for the work, @eth3lbert! :)

@Turbo87 Turbo87 merged commit 2815750 into rust-lang:main Jan 19, 2024
@eth3lbert eth3lbert deleted the count-subq branch January 19, 2024 12:53
carols10cents added a commit that referenced this pull request Feb 2, 2024
This reverts commit 2815750, reversing
changes made to f4ef9a7.
LawnGnome added a commit that referenced this pull request Feb 2, 2024
Revert "Merge pull request #7941 from eth3lbert/count-subq"
@carols10cents
Copy link
Member

Cross-referencing here: we had to revert this PR because it broke search queries with spaces in them. New issue for re-landing: #8052

@eth3lbert eth3lbert restored the count-subq branch February 2, 2024 03:01
Turbo87 added a commit that referenced this pull request Feb 6, 2024
Re-introducing improve crates endpoint performance (#7941)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-backend ⚙️ C-enhancement ✨ Category: Adding new behavior or a change to the way an existing feature works
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants