|
14 | 14 | from sentry.models.organization import Organization |
15 | 15 | from sentry.models.project import Project |
16 | 16 | from sentry.search.events.types import SnubaParams |
17 | | -from sentry.seer.autofix.utils import get_autofix_repos_from_project_code_mappings |
| 17 | +from sentry.seer.autofix.utils import ( |
| 18 | + bulk_get_project_preferences, |
| 19 | + get_autofix_repos_from_project_code_mappings, |
| 20 | +) |
18 | 21 | from sentry.seer.explorer.context_engine_utils import ( |
19 | 22 | EVENT_COUNT_LOOKBACK_DAYS, |
20 | 23 | ProjectEventCounts, |
@@ -245,28 +248,40 @@ def index_repos(organization_id: int, *args, **kwargs) -> None: |
245 | 248 | projects = list( |
246 | 249 | Project.objects.filter(organization_id=organization_id, status=ObjectStatus.ACTIVE) |
247 | 250 | ) |
| 251 | + project_map = {p.id: p for p in projects} |
248 | 252 |
|
249 | | - if not projects: |
| 253 | + if not project_map: |
250 | 254 | logger.info("No projects found for organization", extra={"org_id": organization_id}) |
251 | 255 | return |
252 | 256 |
|
253 | 257 | org_repo_definitions: dict[tuple[str, str, str], RepoDetails] = {} |
254 | 258 |
|
255 | | - for project in projects: |
256 | | - repos = get_autofix_repos_from_project_code_mappings(project) |
| 259 | + preferences_by_id = bulk_get_project_preferences(organization_id, list(project_map.keys())) |
| 260 | + |
| 261 | + for project_id, project in project_map.items(): |
| 262 | + existing_pref = preferences_by_id.get(str(project_id)) |
| 263 | + project_pref_repos = existing_pref.get("repositories") or [] |
| 264 | + autofix_repos = get_autofix_repos_from_project_code_mappings(project_map[project_id]) |
| 265 | + |
| 266 | + language_map: dict[tuple[str, str, str], list[str]] = {} |
| 267 | + for autofix_repo in autofix_repos: |
| 268 | + key = (autofix_repo["provider"], autofix_repo["owner"], autofix_repo["name"]) |
| 269 | + language_map[key] = autofix_repo["languages"] |
| 270 | + |
| 271 | + repos = project_pref_repos if project_pref_repos else autofix_repos |
257 | 272 | for repo in repos: |
258 | 273 | key = (repo["provider"], repo["owner"], repo["name"]) |
259 | 274 | if key in org_repo_definitions: |
260 | 275 | repo_definition = org_repo_definitions[key] |
261 | | - repo_definition["project_ids"].append(project.id) |
| 276 | + repo_definition["project_ids"].append(project_id) |
262 | 277 | else: |
263 | 278 | org_repo_definitions[key] = { |
264 | | - "project_ids": [project.id], |
| 279 | + "project_ids": [project_id], |
265 | 280 | "provider": repo["provider"], |
266 | 281 | "owner": repo["owner"], |
267 | 282 | "name": repo["name"], |
268 | 283 | "external_id": repo["external_id"], |
269 | | - "languages": repo["languages"], |
| 284 | + "languages": language_map.get(key, []), |
270 | 285 | "integration_id": repo["integration_id"], |
271 | 286 | } |
272 | 287 |
|
|
0 commit comments