Skip to content
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

Optimize Home Page Data Fetching and Caching #2407

Merged
merged 2 commits into from
Jul 8, 2024

Conversation

JisanAR03
Copy link
Contributor

@JisanAR03 JisanAR03 commented Jul 6, 2024

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:

  • (Updated): Prefetches related objects in a single query, reducing the number of database hits. This approach is generally more efficient when dealing with a large number of related objects, as it minimizes the number of separate queries.
  • (Previous): Issues separate queries for each bug to fetch related screenshots. This results in a larger number of queries, which can be significantly slower if the number of issues is large.

Memory Usage:

  • (Updated): Prefetches related objects only for the current page, making it more memory-efficient by loading only the necessary data into memory.
  • (Previous): Loads all issues and then filters screenshots iteratively, potentially using more memory as it processes all issues before pagination.

Query Efficiency:

  • (Updated): More efficient due to prefetching, which is optimized for fetching related objects in Django.
  • (Previous): Less efficient due to issuing separate queries for each issue’s related screenshots.

Changes Made

  1. Optimized Data Fetching: Used prefetch_related to fetch related objects in a single query, significantly reducing the number of database hits.
  2. Memory Usage Optimization: Prefetches only the necessary data for the current page, ensuring more efficient memory usage.
  3. Removed cache_per_user Decorator: With these optimizations, the cache_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 ?

Copy link

sentry-io bot commented Jul 6, 2024

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: website/views.py

Function Unhandled Issue
newhome AttributeError: 'AnonymousUser' object has no attribute 'email' ...
Event Count: 3

Did you find this useful? React with a 👍 or 👎

@JisanAR03 JisanAR03 enabled auto-merge July 8, 2024 13:28
@JisanAR03 JisanAR03 merged commit ee9f128 into OWASP-BLT:main Jul 8, 2024
8 checks passed
@JisanAR03 JisanAR03 deleted the home_page_optimize branch July 9, 2024 15:23
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.

None yet

2 participants