Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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 ?

@sentry
Copy link

sentry 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 mentioned this pull request Jul 8, 2024
@JisanAR03 JisanAR03 enabled auto-merge July 8, 2024 13:28
@JisanAR03 JisanAR03 merged commit ee9f128 into OWASP-BLT:main Jul 8, 2024
@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.

2 participants