Improve N+1 preloading for when boundary_type is aliased / not a direct association

The following discussion from !242438 (merged) should be addressed:

  • @alexbuijs started a discussion: (+1 comment)

    This silently no-ops for a couple of common list types, so the N+1 we're fixing still happens for them:

    • MergeRequestType declares boundary: :project, but that's alias_method :project, :target_project — reflect_on_association(:project) is nil (the reflection is :target_project). It also uses present_using MergeRequestPresenter, so it's already skipped at the respond_to?(:reflect_on_association) guard on L59.
    • Ci::RunnerType's boundary: :owner is a def owner, not an association.

    Only projects has an N+1 regression test, so MR/runner lists aren't covered. Could we handle aliased / presenter-wrapped boundaries here (e.g. declaring boundary: :target_project)?

Possible solutions

  • MergeRequestType -> so if we were to change boundary_method: :target_project, that would be okay?
  • Ci::RunnerType -> We can extend the preloading to use the directive:
authorize_granular_token(
  permissions: :read_runner,
  boundaries: [...],
  preload: [{ owner_runner_project: :project }, { owner_runner_namespace: :namespace }, :creator]
)
Edited by 🤖 GitLab Bot 🤖