-
-
Notifications
You must be signed in to change notification settings - Fork 884
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
Speed up GET /api/v3/site endpoint #4245
Conversation
Great!! But in my case all the slowdown is caused by a single line:
which is untouched in your commit. Do you have any clues why something as simple as retrieving the admins would take almost a full second? |
CommunityModeratorView::for_person(context.inner_pool(), person_id), | ||
LocalUserLanguage::read(context.inner_pool(), local_user_id) | ||
) | ||
.with_lemmy_type(LemmyErrorType::SystemErrLogin)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it would be much better to read all this data in a single SQL query, but it also seems harder to implement.
crates/api_crud/src/site/read.rs
Outdated
PersonBlockView::for_person(context.inner_pool(), person_id), | ||
CommunityModeratorView::for_person(context.inner_pool(), person_id), | ||
LocalUserLanguage::read(context.inner_pool(), local_user_id) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of changing the functions to use ActualDbPool, you can replace this with:
lemmy_db_schema::try_join_with_pool!(pool => (
|pool| CommunityFollowerView::for_person(pool, person_id),
|pool| CommunityBlockView::for_person(pool, person_id),
|pool| InstanceBlockView::for_person(pool, person_id),
|pool| PersonBlockView::for_person(pool, person_id),
|pool| CommunityModeratorView::for_person(pool, person_id),
|pool| LocalUserLanguage::read(pool, local_user_id)
))
Pool variable must be defined first because the macro only accepts an identifier:
let pool = context.pool();
The queries for building site_response can also run in parallel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice I didnt see that macro, works perfectly.
Adds two commits:
try_join
. This required changes to db methods to avoid overlapping &mut borrows of the same value. Luckily these methods are only used in few other places.GetSiteResponse
is independent from the user account, so we can easily cache it across requests.cc @dullbananas