|
19 | 19 | PackageOverlay, |
20 | 20 | ReferenceUrlOverlay, |
21 | 21 | ) |
22 | | -from shared.models.nix_evaluation import get_major_channel |
23 | 22 |
|
24 | 23 | logger = logging.getLogger(__name__) |
25 | 24 |
|
@@ -211,8 +210,9 @@ def cache_new_suggestions(suggestion: CVEDerivationClusterProposal) -> None: |
211 | 210 | "metadata", |
212 | 211 | "package_link__package", |
213 | 212 | "parent_evaluation", |
214 | | - "parent_evaluation__channel", |
| 213 | + "parent_evaluation__branch", |
215 | 214 | ) |
| 215 | + .prefetch_related("parent_evaluation__branch__channels") |
216 | 216 | .prefetch_related( |
217 | 217 | Prefetch( |
218 | 218 | "metadata__maintainers", |
@@ -316,69 +316,61 @@ def channel_structure( |
316 | 316 | packages[attribute_path].derivation_ids.append(derivation.pk) |
317 | 317 | if ( |
318 | 318 | derivation.metadata |
319 | | - and derivation.parent_evaluation.channel.is_tracking_branch |
| 319 | + and derivation.parent_evaluation.branch.is_tracking_branch |
320 | 320 | ): |
321 | 321 | packages[attribute_path].description = derivation.metadata.get_description() |
322 | 322 | packages[attribute_path].maintainers = [ |
323 | 323 | CachedSuggestion.Maintainer.model_validate(to_dict(m)) |
324 | 324 | for m in derivation.metadata.prefetched_maintainers |
325 | 325 | ] |
326 | | - # Get the branch from which that derivation originates |
327 | | - branch_name = derivation.parent_evaluation.channel.channel_branch |
328 | | - # Get primary ("major") channel to which that branch belongs |
329 | | - major_channel = get_major_channel(branch_name) |
330 | | - # FIXME This quietly drops unfamiliar branch names |
331 | | - if major_channel: |
332 | | - # XXX(@fricklerhandwerk): Here we assign package information to channel names in iteration order, which in the query we have established to be oldest-first by evaluation time. |
333 | | - channels = packages[attribute_path].channels |
334 | | - if major_channel not in channels: |
335 | | - channels[major_channel] = CachedSuggestion.PackageOnPrimaryChannel( |
336 | | - major_version=None, |
337 | | - status=None, |
338 | | - src_position=None, |
339 | | - # XXX(@fricklerhandwerk): If this is not replaced in subsequent processing, it will display "-" |
340 | | - uniform_versions=None, |
341 | | - sub_branches=dict(), |
342 | | - updated=None, |
343 | | - ) |
344 | | - if branch_name == major_channel: |
345 | | - channels[major_channel] = CachedSuggestion.PackageOnPrimaryChannel( |
| 326 | + all_channels = list(derivation.parent_evaluation.branch.channels.all()) |
| 327 | + status = is_version_affected( |
| 328 | + [c.affects(package_version) for c in version_constraints] |
| 329 | + ) |
| 330 | + src_position = get_src_position(derivation) |
| 331 | + updated = derivation.parent_evaluation.updated_at |
| 332 | + if len(all_channels) > 1: |
| 333 | + # Old style: multiple channels were evaluated separately. |
| 334 | + # Display under the primary channel with others nested. |
| 335 | + # FIXME(@fricklerhandwerk): Ideally we'd garbage-collect all those evaluations, |
| 336 | + # except the one with the latest commit. |
| 337 | + # That would require knowing the order of evaluation commits: |
| 338 | + # https://docs.github.com/en/rest/commits/commits?apiVersion=2026-03-10#compare-two-commits |
| 339 | + primary = next((c for c in all_channels if c.primary), None) |
| 340 | + if primary is None: |
| 341 | + continue |
| 342 | + group_name = primary.channel_branch |
| 343 | + packages[attribute_path].channels[group_name] = ( |
| 344 | + CachedSuggestion.PackageOnPrimaryChannel( |
346 | 345 | major_version=package_version, |
347 | | - status=is_version_affected( |
348 | | - [c.affects(package_version) for c in version_constraints] |
349 | | - ), |
350 | | - src_position=get_src_position(derivation), |
351 | | - uniform_versions=channels[major_channel].uniform_versions, |
352 | | - sub_branches=channels[major_channel].sub_branches, |
353 | | - updated=derivation.parent_evaluation.updated_at, |
| 346 | + status=status, |
| 347 | + src_position=src_position, |
| 348 | + uniform_versions=True, |
| 349 | + sub_branches={ |
| 350 | + c.channel_branch: CachedSuggestion.PackageOnBranch( |
| 351 | + version=package_version, |
| 352 | + status=status, |
| 353 | + src_position=src_position, |
| 354 | + updated=updated, |
| 355 | + ) |
| 356 | + for c in all_channels |
| 357 | + if not c.primary |
| 358 | + }, |
| 359 | + updated=updated, |
354 | 360 | ) |
355 | | - else: |
356 | | - channels[major_channel].sub_branches[branch_name] = ( |
357 | | - CachedSuggestion.PackageOnBranch( |
358 | | - version=package_version, |
359 | | - status=is_version_affected( |
360 | | - [c.affects(package_version) for c in version_constraints] |
361 | | - ), |
362 | | - src_position=get_src_position(derivation), |
363 | | - updated=derivation.parent_evaluation.updated_at, |
364 | | - ) |
365 | | - ) |
366 | | - |
367 | | - for package_name in packages: |
368 | | - channels = packages[package_name].channels |
369 | | - for mc in channels.keys(): |
370 | | - uniform_versions = True |
371 | | - major_version = channels[mc].major_version |
372 | | - for _, branch in channels[mc].sub_branches.items(): |
373 | | - uniform_versions = ( |
374 | | - uniform_versions and str(major_version) == branch.version |
375 | | - ) |
376 | | - channels[mc].uniform_versions = uniform_versions |
377 | | - # We just sort branch names by length to get a good-enough order |
378 | | - channels[mc].sub_branches = dict( |
379 | | - sorted( |
380 | | - channels[mc].sub_branches.items(), |
381 | | - reverse=True, |
| 361 | + ) |
| 362 | + else: |
| 363 | + # New style: evaluations per release branch. |
| 364 | + # Display the version for each branch separately |
| 365 | + group_name = derivation.parent_evaluation.branch.name |
| 366 | + packages[attribute_path].channels[group_name] = ( |
| 367 | + CachedSuggestion.PackageOnPrimaryChannel( |
| 368 | + major_version=package_version, |
| 369 | + status=status, |
| 370 | + src_position=src_position, |
| 371 | + uniform_versions=True, |
| 372 | + sub_branches={}, |
| 373 | + updated=updated, |
382 | 374 | ) |
383 | 375 | ) |
384 | 376 | return packages |
|
0 commit comments