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

Rank OWASP Nest community users using total contributions. #1000

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ahmedxgouda
Copy link
Collaborator

Resolves #973

  • Added a property idx_contributions_count to the UserIndexMixin that returns the total number of contributions made by the contributor to OWASP.
  • Included this property in the UserIndex.
  • Placed the property at the top of the customRanking.

@ahmedxgouda ahmedxgouda requested a review from arkid15r as a code owner March 4, 2025 05:34
Copy link

coderabbitai bot commented Mar 4, 2025

Summary by CodeRabbit

  • New Features
    • Enhanced user record ranking by incorporating a new metric based on user contributions. With this improvement, users with higher contributions now receive more prominent placement during searches and listings.

Walkthrough

This pull request introduces a new field, idx_contributions_count, to the UserIndex class for Algolia index configuration, which is now included in the custom ranking criteria as desc(idx_contributions_count). Additionally, a property method idx_contributions_count is added to the UserIndexMixin class, which calculates the total contributions for a user by aggregating data from the RepositoryContributor model. These modifications enhance the user ranking mechanism based on contributions.

Changes

Files Changes
backend/apps/github/index/user.py * Added idx_contributions_count field in UserIndex and updated custom ranking to include desc(idx_contributions_count).
backend/apps/github/models/mixins/user.py * Introduced idx_contributions_count method in UserIndexMixin to calculate total contributions for a user.

Suggested reviewers

  • arkid15r

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 345e170 and 2e9264b.

📒 Files selected for processing (1)
  • backend/apps/github/models/mixins/user.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/apps/github/models/mixins/user.py
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: CodeQL (python)
  • GitHub Check: Run frontend e2e tests
  • GitHub Check: Run frontend unit tests
  • GitHub Check: CodeQL (javascript-typescript)
  • GitHub Check: Run backend tests

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
backend/apps/github/models/mixins/user.py (1)

110-117: Optimize database query with aggregation

While the current implementation correctly calculates the total contributions count, it fetches all repository contributor records and performs the sum in Python. This could be inefficient for users with many repository contributions.

Consider using Django's aggregation functionality to calculate the sum at the database level:

@property
def idx_contributions_count(self):
    """Return contributions count for indexing."""
-    contributions_counts = [
-        rc.contributions_count for rc in RepositoryContributor.objects.filter(user=self)
-    ]
-    return sum(contributions_counts)
+    from django.db.models import Sum
+    result = RepositoryContributor.objects.filter(user=self).aggregate(
+        total=Sum('contributions_count')
+    )
+    return result['total'] or 0

This approach performs the calculation in a single database query rather than loading all records into memory.

backend/apps/github/index/user.py (1)

44-47: Consider documenting the ranking criteria

The custom ranking now prioritizes contributions count, followed by creation date and followers count. This logic is important for understanding how users are presented in the UI.

Consider adding a comment to explain the ranking priority:

"customRanking": [
    "desc(idx_contributions_count)",  # Prioritize users with more contributions
    "desc(idx_created_at)",          # Then by account age (newer first)
    "desc(idx_followers_count)",     # Then by popularity
],
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 76b9347 and 0a0282e.

📒 Files selected for processing (2)
  • backend/apps/github/index/user.py (2 hunks)
  • backend/apps/github/models/mixins/user.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: CodeQL (python)
  • GitHub Check: Run frontend e2e tests
  • GitHub Check: Run frontend unit tests
  • GitHub Check: CodeQL (javascript-typescript)
  • GitHub Check: Run backend tests
🔇 Additional comments (3)
backend/apps/github/index/user.py (3)

19-19: Field addition aligns with PR goal - looks good!

The addition of the idx_contributions_count field to the index configuration enables the indexing of user contribution counts, which is essential for the new ranking feature.


44-44: Custom ranking implementation matches requirements

Placing desc(idx_contributions_count) at the top of the custom ranking list correctly prioritizes users with higher contribution counts in search results, which aligns perfectly with the PR objective of ranking OWASP Nest community users based on their total contributions.


19-19:

❓ Verification inconclusive

Verify the impact of the contribution count ranking

The changes implement the requested feature, but it would be beneficial to understand how this affects the actual user ranking in the UI. Consider testing with a representative dataset to ensure the ranking reflects the expected order of users.

Also applies to: 44-44


🏁 Script executed:

#!/bin/bash
# Check if there are any tests that verify the ranking behavior

echo "Searching for user index or ranking tests..."
fd "test.*user.*\.(py|js)" --exclude node_modules

echo "Looking for user ranking logic on frontend..."
rg -A 3 -B 3 "contribution|ranking" --glob "frontend/**/*.{js,jsx,ts,tsx}"

Length of output: 26046


Action: Validate UI Ranking Consistency with Contribution Count

The updated index "idx_contributions_count" appears to integrate the contribution count into our ranking mechanism correctly. However, as our frontend mock data (e.g., in various test files) relies on the contributionsCount field, please verify that the actual user ranking in the UI reflects the intended order when using a representative dataset. In other words, ensure that users are sorted as expected according to their contributions. This check is applicable to both the change at line 19 and the corresponding update at line 44 in backend/apps/github/index/user.py.

contributions_counts = [
rc.contributions_count for rc in RepositoryContributor.objects.filter(user=self)
]
return sum(contributions_counts)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you do it with Django ORM only? It's faster.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the feedback.

Copy link

sonarqubecloud bot commented Mar 4, 2025

@ahmedxgouda ahmedxgouda requested a review from arkid15r March 4, 2025 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rank OWASP Nest community users using total contributions
2 participants