From 0a0282e86cf30fd7ecbff7a080532125af03b809 Mon Sep 17 00:00:00 2001 From: Ahmed Gouda <62152210+ahmedxgouda@users.noreply.github.com> Date: Tue, 4 Mar 2025 05:28:34 +0000 Subject: [PATCH] Rank OWASP Nest community users using total contributions. --- backend/apps/github/index/user.py | 2 ++ backend/apps/github/models/mixins/user.py | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/backend/apps/github/index/user.py b/backend/apps/github/index/user.py index c0bde5d7e..75f35313e 100644 --- a/backend/apps/github/index/user.py +++ b/backend/apps/github/index/user.py @@ -16,6 +16,7 @@ class UserIndex(IndexBase): "idx_bio", "idx_company", "idx_contributions", + "idx_contributions_count", "idx_created_at", "idx_email", "idx_followers_count", @@ -40,6 +41,7 @@ class UserIndex(IndexBase): "attributeForDistinct": "idx_login", "minProximity": 4, "customRanking": [ + "desc(idx_contributions_count)", "desc(idx_created_at)", "desc(idx_followers_count)", ], diff --git a/backend/apps/github/models/mixins/user.py b/backend/apps/github/models/mixins/user.py index ac8aa1b6c..e30a2869a 100644 --- a/backend/apps/github/models/mixins/user.py +++ b/backend/apps/github/models/mixins/user.py @@ -107,6 +107,14 @@ def idx_contributions(self): .select_related("repository")[:TOP_REPOSITORY_CONTRIBUTORS_LIMIT] ] + @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) + @property def idx_issues(self): """Return issues for indexing."""