Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions core/commands/repository/interactors/fetch_repository.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sentry_sdk
from asgiref.sync import sync_to_async
from shared.django_apps.codecov_auth.models import Owner
from shared.django_apps.core.models import Repository
Expand All @@ -7,23 +8,32 @@

class FetchRepositoryInteractor(BaseInteractor):
@sync_to_async
@sentry_sdk.trace
def execute(
self,
owner: Owner,
name: str,
okta_authenticated_accounts: list[int],
exclude_okta_enforced_repos: bool = True,
):
) -> Repository | None:
queryset = Repository.objects.viewable_repos(self.current_owner)
if exclude_okta_enforced_repos:
queryset = queryset.exclude_accounts_enforced_okta(
okta_authenticated_accounts
)

return (
# TODO(swatinem): We should find a way to avoid these combinators:
# The `with_recent_coverage` combinator is quite expensive.
# We only need that in case we want to query these props via graphql:
# `coverageAnalytics.{percentCovered,commitSha,hits,misses,lines}`
# Similarly, `with_oldest_commit_at` is only needed for `oldestCommitAt`.
Comment on lines +25 to +29
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The query generated by the combinators below is this:
https://codecov.sentry.io/insights/backend/database/spans/span/fbbb13620d0da28b/?project=5215654&statsPeriod=30d
As you can see, it is incredibly complex, and also slow.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

note to self:
mirumee/ariadne#1116 (comment)
this snippet might help achieve that goal. but by god why that is not part of the standard graphql tooling is beyond me. this looks like fundamental functionality that should just exist out of the box.


repo = (
queryset.filter(author=owner, name=name)
.with_recent_coverage()
.with_oldest_commit_at()
.select_related("author")
.first()
)

return repo
2 changes: 1 addition & 1 deletion core/commands/repository/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def fetch_repository(
name: str,
okta_authenticated_accounts: list[int],
exclude_okta_enforced_repos: bool = True,
) -> Repository:
) -> Repository | None:
return self.get_interactor(FetchRepositoryInteractor).execute(
owner,
name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def resolve_coverage_analytics_result_type(


@coverage_analytics_bindable.field("percentCovered")
@sentry_sdk.trace
def resolve_percent_covered(
parent: CoverageAnalyticsProps, info: GraphQLResolveInfo
) -> Optional[float]:
Expand Down
14 changes: 13 additions & 1 deletion graphql_api/types/owner/owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from hashlib import sha1
from typing import Any, Coroutine, Iterable, List, Optional

import sentry_sdk
import shared.rate_limits as rate_limits
import stripe
import yaml
Expand Down Expand Up @@ -168,7 +169,7 @@ async def resolve_repository(
# This means we do not want to filter out the Okta enforced repos
exclude_okta_enforced_repos = not is_impersonation

repository: Optional[Repository] = await command.fetch_repository(
repository: Repository | None = await command.fetch_repository(
owner,
name,
okta_authenticated_accounts,
Expand All @@ -178,6 +179,17 @@ async def resolve_repository(
if repository is None:
return NotFoundError()

sentry_sdk.set_tags(
{
"owner_username": repository.author.username,
"owner_service": repository.author.service,
"owner_plan": repository.author.plan,
"owner_id": repository.author.ownerid,
"repo_name": repository.name,
"repo_id": repository.repoid,
}
)

current_owner = info.context["request"].current_owner
has_products_enabled = (
repository.bundle_analysis_enabled
Expand Down
17 changes: 10 additions & 7 deletions graphql_api/types/repository/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from datetime import datetime
from typing import Any, Dict, List, Optional

import sentry_sdk
import shared.rate_limits as rate_limits
import yaml
from ariadne import ObjectType, UnionType
Expand Down Expand Up @@ -74,9 +75,14 @@ def resolve_author(repository: Repository, info: GraphQLResolveInfo) -> Owner:


@repository_bindable.field("commit")
def resolve_commit(repository: Repository, info: GraphQLResolveInfo, id: int) -> Commit:
def resolve_commit(repository: Repository, info: GraphQLResolveInfo, id: str) -> Commit:
loader = CommitLoader.loader(info, repository.pk)
return loader.load(id)
commit = loader.load(id)

if commit:
sentry_sdk.set_tag("commit_sha", id)

return commit


@repository_bindable.field("uploadToken")
Expand Down Expand Up @@ -305,12 +311,9 @@ def resolve_is_github_rate_limited(

@repository_bindable.field("coverageAnalytics")
def resolve_coverage_analytics(
repository: Repository,
info: GraphQLResolveInfo,
repository: Repository, info: GraphQLResolveInfo
) -> CoverageAnalyticsProps:
return CoverageAnalyticsProps(
repository=repository,
)
return CoverageAnalyticsProps(repository=repository)


@repository_bindable.field("testAnalytics")
Expand Down
Loading