-
Notifications
You must be signed in to change notification settings - Fork 10
[t3][do not review] feat: enhance branch listing with activity metrics #491
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| from typing import Any | ||
|
|
||
| from asgiref.sync import sync_to_async | ||
| from django.db import models | ||
| from django.db.models import OuterRef, Q, QuerySet, Subquery | ||
|
|
||
| from codecov.commands.base import BaseInteractor | ||
|
|
@@ -36,4 +37,28 @@ def execute(self, repository: Repository, filters: dict[str, Any]) -> QuerySet: | |
| | Q(name=repository.branch) # but always include the default branch | ||
| ) | ||
|
|
||
| # Enhance branch information with latest commit activity metrics | ||
| if filters.get("include_activity_metrics", True): | ||
| queryset = queryset.annotate( | ||
| latest_commit_timestamp=Subquery( | ||
| Commit.objects.filter( | ||
| repository_id=OuterRef("repository__repoid"), | ||
| branch=OuterRef("branch"), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential bug: The subquery uses
|
||
| deleted=False, | ||
| ) | ||
| .order_by("-timestamp") | ||
|
Comment on lines
+44
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The While this might work due to the db_column mapping, it's inconsistent with Django ORM best practices and could lead to confusion or issues in different contexts. Did we get this right? 👍 / 👎 to inform future reviews. |
||
| .values("timestamp")[:1] | ||
| ), | ||
| total_commits_count=Subquery( | ||
| Commit.objects.filter( | ||
| repository_id=OuterRef("repository__repoid"), | ||
| branch=OuterRef("branch"), | ||
|
Comment on lines
+48
to
+55
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Did we get this right? 👍 / 👎 to inform future reviews. |
||
| deleted=False, | ||
|
Comment on lines
+41
to
+56
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These subqueries will execute for every branch in the result set, which could cause significant performance issues for repositories with many branches. Consider adding database indexes on (repository_id, branch, deleted) and (repository_id, branch, timestamp) for the Commit model. Also consider implementing pagination or limiting the number of branches processed when activity metrics are enabled. Did we get this right? 👍 / 👎 to inform future reviews. |
||
| ) | ||
| .values("repository_id") | ||
| .annotate(count=models.Count("id")) | ||
| .values("count")[:1] | ||
| ), | ||
|
Comment on lines
+52
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Did we get this right? 👍 / 👎 to inform future reviews. |
||
| ) | ||
|
|
||
| return queryset | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value for
include_activity_metricsisTrue, which means these potentially expensive subqueries will be executed for all branch fetches unless explicitly disabled. This could have significant performance implications for repositories with many branches and commits.Consider:
Falseand requiring callers to opt-in(repository_id, branch, deleted, timestamp)for the Commit modelDid we get this right? 👍 / 👎 to inform future reviews.