ref(autopilot): Limit missing integration detector to JS and python#107398
Conversation
src/sentry/autopilot/tasks.py
Outdated
| # Get the repository mapped to each project via RepositoryProjectPathConfig | ||
| repo_configs = RepositoryProjectPathConfig.objects.filter( | ||
| project__in=projects, | ||
| repository__status=ObjectStatus.ACTIVE, | ||
| ).select_related("repository") | ||
|
|
||
| repo_config_by_project_id = {config.project_id: config for config in repo_configs} | ||
|
|
||
| for project in projects: | ||
| repo_config = repo_config_by_project_id.get(project.id) |
There was a problem hiding this comment.
Moved the query out of the loop
constantinius
left a comment
There was a problem hiding this comment.
Looks clean. I like the Q() trick
src/sentry/autopilot/tasks.py
Outdated
| platform_filter = Q() | ||
| for prefix in SupportedPlatformPrefix: | ||
| platform_filter |= Q(platform__startswith=prefix) | ||
|
|
||
| projects = Project.objects.filter( | ||
| platform_filter, | ||
| organization=organization, | ||
| ).all() | ||
|
|
||
| if len(projects) == 0: | ||
| return | ||
|
|
||
| for project in projects: | ||
| # Get the repository mapped to this project via RepositoryProjectPathConfig | ||
| repo_config = ( | ||
| RepositoryProjectPathConfig.objects.filter( | ||
| project=project, | ||
| repository__status=ObjectStatus.ACTIVE, | ||
| ) | ||
| .select_related("repository") | ||
| .first() | ||
| ) | ||
| # Get the repository mapped to each project via RepositoryProjectPathConfig | ||
| repo_configs = RepositoryProjectPathConfig.objects.filter( | ||
| project__in=projects, | ||
| repository__status=ObjectStatus.ACTIVE, | ||
| ).select_related("repository") | ||
|
|
||
| repo_config_by_project_id = {config.project_id: config for config in repo_configs} |
There was a problem hiding this comment.
I think this can be simplified - and then all you need to do is iterate over the configs returned:
| platform_filter = Q() | |
| for prefix in SupportedPlatformPrefix: | |
| platform_filter |= Q(platform__startswith=prefix) | |
| projects = Project.objects.filter( | |
| platform_filter, | |
| organization=organization, | |
| ).all() | |
| if len(projects) == 0: | |
| return | |
| for project in projects: | |
| # Get the repository mapped to this project via RepositoryProjectPathConfig | |
| repo_config = ( | |
| RepositoryProjectPathConfig.objects.filter( | |
| project=project, | |
| repository__status=ObjectStatus.ACTIVE, | |
| ) | |
| .select_related("repository") | |
| .first() | |
| ) | |
| # Get the repository mapped to each project via RepositoryProjectPathConfig | |
| repo_configs = RepositoryProjectPathConfig.objects.filter( | |
| project__in=projects, | |
| repository__status=ObjectStatus.ACTIVE, | |
| ).select_related("repository") | |
| repo_config_by_project_id = {config.project_id: config for config in repo_configs} | |
| platform_filter = Q() | |
| for prefix in SupportedPlatformPrefix: | |
| platform_filter |= Q(project__platform__startswith=prefix) | |
| # Query RepositoryProjectPathConfig directly with platform filter on the related project | |
| # This avoids fetching projects that don't have repo configs | |
| repo_configs = RepositoryProjectPathConfig.objects.filter( | |
| platform_filter, | |
| project__organization=organization, | |
| repository__status=ObjectStatus.ACTIVE, | |
| ).select_related("repository")``` |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| project__organization=organization, | ||
| repository__status=ObjectStatus.ACTIVE, | ||
| ) | ||
| .select_related("repository") |
There was a problem hiding this comment.
Ineffective select_related before values() call
Low Severity
The .select_related("repository") call on line 286 has no effect because it's immediately followed by .values(). In Django, select_related() optimizes access to related model instances, but values() returns dictionaries. Django automatically creates the necessary JOIN for repository__name in the values() call, making select_related() redundant dead code.
…107398) For other platforms, we cannot rely on the docs yet to give us the information we need. Fixed docs URL for python.


For other platforms, we cannot rely on the docs yet to give us the information we need.
Fixed docs URL for python.