Backport `disable_joins` to enable usage of cross-DB relations
As part of identified changes of [PoC](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/62092) is to backport support for `disable_joins`. `disable_joins` allows to mark passthrough relations as having to use `pluck` instead of `cross-joins`. This is essential if the relation defines a model living in another DB. ```ruby class Runner has_many :projects, through: :runner_projects, disable_joins: true end ``` Related: - Initial backport: https://gitlab.com/gitlab-org/gitlab/-/blob/6284efc3560b0d7d6aa216e0de0a2e2f154b89e0/config/initializers/00_rails_disable_joins.rb - Initial backport: https://gitlab.com/gitlab-org/gitlab/-/blob/6284efc3560b0d7d6aa216e0de0a2e2f154b89e0/config/initializers/00_rails_disable_joins_on_joins.rb - https://github.com/rails/rails/pull/41937 - https://github.com/rails/rails/pull/42079 - https://github.blog/2021-07-12-adding-support-cross-cluster-associations-rails-7/ ## Proposal 1. Backport `disable_joins` in a vanila way: 1-to-1 change 1. Since usage of `disable_joins` might have negative impact we need have a way to dynamically toggle the feature to validate this on production 1. Add additional (temporary feature) on top of disable joins to allow this to by feature-flagged (this should be done on top of backport, the best as an additional mixin). We should remove it as soon as possible as no longer needed. ```ruby class Runner # allow to feature flag disable join usage to rollout it to the production as it might has_many :projects, through: :runner_projects, disable_joins: -> { Feature.enabled?(:ci_runner_projects_disable_joins) } end ```
issue