-
-
Notifications
You must be signed in to change notification settings - Fork 629
Extend user model with total contributions field. #1209
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
Merged
Merged
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
d88ac24
Add contributions_count field to User model and update related logic.
ahmedxgouda 64f8a2c
Refactor User model to calculate contributions_count during data upda…
ahmedxgouda b893bfc
Add contributionsCount to user queries and update UserDetails page.
ahmedxgouda 68effca
Merge branch 'main' into feature/extend-user-model
ahmedxgouda ad1fe32
Update backend tests.
ahmedxgouda 798dbf5
Update frontend tests.
ahmedxgouda c6e5a38
Merge branch 'origin/main' into feature/extend-user-model
ahmedxgouda 7f037e9
Resolve conflicts
ahmedxgouda 2ecf778
Merge rbranch 'origin/main' into feature/extend-user-model
ahmedxgouda afd46dd
Merge branch 'main' into feature/extend-user-model
ahmedxgouda 50e6cb4
Merge branch 'main' into feature/extend-user-model
ahmedxgouda e0e9875
Merge branch 'main' into feature/extend-user-model
ahmedxgouda 69b042d
Merge branch 'main' into feature/extend-user-model
ahmedxgouda 1dc1932
Merge branch 'main' into feature/extend-user-model
ahmedxgouda ac783a3
Merge branch 'main' into feature/extend-user-model
ahmedxgouda 0bb56d3
Add contributions_count field to user model in migrations
ahmedxgouda 9441988
Refactor migration file for user contributions count to use consisten…
ahmedxgouda 28de9e5
Merge branch 'main' into feature/extend-user-model
ahmedxgouda e94b231
Resolve conflicts
ahmedxgouda 0e67617
Merge migrations
ahmedxgouda 8ef9c6e
Refactor migration dependencies formatting
ahmedxgouda abbc3bb
Merge branch 'main' into feature/extend-user-model
ahmedxgouda 6515c19
Merge branch 'main' into pr/ahmedxgouda/1209
arkid15r 66c1723
Update code
arkid15r e087f58
Optimize code
arkid15r File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
backend/apps/github/management/commands/github_update_users.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| """A command to update GitHub users.""" | ||
|
|
||
| import logging | ||
|
|
||
| from django.core.management.base import BaseCommand | ||
| from django.db.models import Sum | ||
|
|
||
| from apps.github.models.repository_contributor import RepositoryContributor | ||
| from apps.github.models.user import User | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| help = "Update GitHub users." | ||
|
|
||
| def add_arguments(self, parser): | ||
| """Add command-line arguments to the parser. | ||
|
|
||
| Args: | ||
| parser (argparse.ArgumentParser): The argument parser instance. | ||
|
|
||
| """ | ||
| parser.add_argument("--offset", default=0, required=False, type=int) | ||
|
|
||
| def handle(self, *args, **options): | ||
| """Handle the command execution. | ||
|
|
||
| Args: | ||
| *args: Variable length argument list. | ||
| **options: Arbitrary keyword arguments containing command options. | ||
|
|
||
| """ | ||
| offset = options["offset"] | ||
| active_users = User.objects.order_by("-created_at") | ||
| active_users_count = active_users.count() | ||
| users = [] | ||
| for idx, user in enumerate(active_users[offset:]): | ||
| prefix = f"{idx + offset + 1} of {active_users_count - offset}" | ||
| print(f"{prefix:<10} {user.title}") | ||
|
|
||
| user.contributions_count = ( | ||
| RepositoryContributor.objects.filter( | ||
| user=user, | ||
| ).aggregate( | ||
| total_contributions=Sum( | ||
| "contributions_count", | ||
| ) | ||
| )["total_contributions"] | ||
| or 0 | ||
| ) | ||
| users.append(user) | ||
|
|
||
| if not len(users) % 1000: | ||
| User.bulk_save(users, fields=("contributions_count",)) | ||
|
|
||
| User.bulk_save(users, fields=("contributions_count",)) | ||
|
arkid15r marked this conversation as resolved.
Outdated
|
||
17 changes: 17 additions & 0 deletions
17
backend/apps/github/migrations/0021_user_contributions_count.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Generated by Django 5.1.7 on 2025-04-07 07:56 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("github", "0020_repositorycontributor_user_contrib_idx"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="user", | ||
| name="contributions_count", | ||
| field=models.IntegerField(default=0, verbose_name="Contributions count"), | ||
| ), | ||
|
ahmedxgouda marked this conversation as resolved.
|
||
| ] | ||
12 changes: 12 additions & 0 deletions
12
backend/apps/github/migrations/0022_merge_20250417_1000.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Generated by Django 5.2 on 2025-04-17 10:00 | ||
|
|
||
| from django.db import migrations | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("github", "0021_release_release_published_at_idx"), | ||
| ("github", "0021_user_contributions_count"), | ||
| ] | ||
|
|
||
| operations = [] |
17 changes: 17 additions & 0 deletions
17
backend/apps/github/migrations/0023_alter_user_contributions_count.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Generated by Django 5.2 on 2025-04-20 02:55 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("github", "0022_merge_20250417_1000"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AlterField( | ||
| model_name="user", | ||
| name="contributions_count", | ||
| field=models.PositiveIntegerField(default=0, verbose_name="Contributions count"), | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.