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

feat: add ProjectBadgeView and RepoBadgeView for tracking project and repo visit counts #3214

Merged
merged 1 commit into from
Jan 10, 2025

Conversation

JisanAR03
Copy link
Contributor

Optimize and Refactor ProjectBadgeView for Enhanced Performance and Accuracy


Description:

This pull request introduces a significant update to the ProjectBadgeView class, focusing on performance optimization, improved logic for tracking unique visits, and better handling of edge cases.

Key Changes:

  1. Optimized Visit Tracking:

    • Introduced logic to handle IP-based visit tracking per day.
    • Ensured that only the first unique visit of the day per IP increments the project's visit count.
    • Simplified IP filtering logic to efficiently check and update visit records.
  2. Improved Logic for Data Management:

    • Added a mechanism to reset IP visit records if the last visit was on a previous day, ensuring accurate daily tracking.
    • Safeguarded against redundant project visit count increments.
  3. Enhanced Visualization:

    • Replaced the old date-based bar graph with a simple, efficient visualization of the total visit count.
    • Improved rendering logic for the badge, making it clearer and more efficient.
  4. Code Simplification and Maintenance:

    • Reduced complexity in managing dates and visit counts.
    • Utilized Django's F expressions for atomic updates to the project visit count, preventing race conditions.
  5. Performance Improvements:

    • Minimized database queries by reusing objects and limiting redundant queries.
    • Optimized the logic for updating or creating IP objects.

Why These Changes?

The old implementation had several inefficiencies:

  • It recalculated visit counts by grouping IPs daily, which was costly and slow for projects with high traffic.
  • It allowed multiple visits from the same IP on the same day to inflate the visit count.
  • The bar chart visualization was unnecessarily complex and misaligned with the requirement to display a single visit count.

The updated code resolves these issues and ensures accurate, efficient, and scalable tracking of project visits.

@DonnieBLT sir , can you please review this new PR ?
another step for fix #2972

Copy link

sentry-io bot commented Jan 10, 2025

🔍 Existing Issues For Review

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

📄 File: website/views/project.py

Function Unhandled Issue
get_context_data AttributeError: 'ProjectListView' object has no attribute 'object_list' ...
Event Count: 2

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

@DonnieBLT DonnieBLT merged commit f7151c0 into OWASP-BLT:main Jan 10, 2025
9 checks passed
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.

create a csv to add all owasp projects to /projects
2 participants