-
-
Notifications
You must be signed in to change notification settings - Fork 10k
Optimize homepage post loading by eliminating N+1 queries for user data #7668
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
Conversation
|
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.
Pull Request Overview
This PR optimizes homepage and archive page loading performance by eliminating N+1 database queries when fetching post data and associated metadata (users, tags, categories, counters). Instead of making individual queries for each post's related data, the implementation now batches these queries by collecting all required IDs upfront and fetching them in bulk operations.
Key changes:
- Introduced batch query methods for users, tags, categories, and counters
- Refactored post list conversion to use bulk operations instead of sequential individual queries
- Added ghost user support for missing user references
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
PostPublicQueryServiceImpl.java | Core optimization - replaced sequential queries with bulk batch operations for post list conversion |
UserServiceImpl.java | Added bulk user query method and moved ghost user constant to interface |
CounterServiceImpl.java | Added batch counter query functionality |
TagFinderImpl.java | Replaced sequential queries with single bulk query using IN operator |
CategoryFinderImpl.java | Replaced sequential queries with single bulk query using IN operator |
ContributorFinderImpl.java | Updated to use new bulk user service method |
ContributorVo.java | Added static ghost user factory method |
PostFinderImpl.java | Updated to use new batch conversion method |
Interface files | Updated method signatures to accept Collection instead of List for better flexibility |
application/src/main/java/run/halo/app/theme/finders/vo/ContributorVo.java
Show resolved
Hide resolved
application/src/main/java/run/halo/app/theme/finders/impl/PostPublicQueryServiceImpl.java
Show resolved
Hide resolved
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.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ruibaby The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind improvement
/area core
/milestone 2.21.x
What this PR does / why we need it:
This PR refactors posts query to reduce database queries significantly.
Which issue(s) this PR fixes:
Fixes #7593
Supersedes #7644
Does this PR introduce a user-facing change?