Optimize Home Page Data Fetching and Caching #2407
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR optimizes the home page by improving how data is fetched and cached, leading to better performance, reduced memory usage, and more maintainable code. Below is a performance comparison between the previous implementation and the updated implementation .
Performance Comparison
Database Queries:
Memory Usage:
Query Efficiency:
Changes Made
prefetch_related
to fetch related objects in a single query, significantly reducing the number of database hits.cache_per_user
Decorator: With these optimizations, thecache_per_user
decorator is no longer necessary for the home page, as the updated implementation handles real-time data updates efficiently.Conclusion
These changes enhance the performance and efficiency of the home page, ensuring that users experience faster load times and up-to-date content. The code is also more readable and easier to maintain, which will benefit future development.
@DonnieBLT , @arkid15r , can you please review sir ?