Move latest-finished rollout selection to the backend

What does this MR do and why?

Environments with more than 20 rollout environments had a correctness problem. environment_card.vue fetched an environment's entire rolloutEnvironments connection (capped at 20 by the resolver) and picked the most recently finished one client-side via filter + reduce. If an environment had more than 20 rollout environments, the actual most-recently-finished one might not be among the 20 returned, so the card could show a stale release version, deploy time, or deployed-by user.

This MR moves the selection to the backend, where it belongs. Two new scopes (finished and most_recently_finished) are added to the Cd::RolloutEnvironment model, along with a latest_finished_per_environment class method (using a DISTINCT ON query, a pattern already used elsewhere in this codebase) that a GraphQL batch loader calls. A new latestFinishedRolloutEnvironment field is exposed on the CdEnvironment GraphQL type (batch-loaded, gated behind the existing ai_native_deploy feature flag, marked as an experimental field targeting milestone 19.4). The frontend query and component are simplified to read this single field directly, which also removes the now-unnecessary client-side filter+reduce logic.

This is not a visual or styling change — the same fields render the same way in the UI, just sourced correctly and more simply now.

References

Screenshots or screen recordings

N/A

How to set up and validate locally

  1. Enable the ai_native_deploy feature flag locally:

    Feature.enable(:ai_native_deploy)
  2. Create data as per the MR description !244679 (merged)

  3. Navigate to an organization's CD environments page.

  4. Confirm the release, last-deploy, and deployed-by fields reflect the backend-selected latest finished rollout environment.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Rajan Mistry

Merge request reports

Loading
Loading