Skip to content

THREESCALE-9973: Bullet n plus 1 offences#4305

Open
madnialihussain wants to merge 8 commits into
masterfrom
bullet-n-plus-1-offences
Open

THREESCALE-9973: Bullet n plus 1 offences#4305
madnialihussain wants to merge 8 commits into
masterfrom
bullet-n-plus-1-offences

Conversation

@madnialihussain
Copy link
Copy Markdown
Contributor

What this PR does / why we need it

This PR removes 10 n_plus_one_query safelist entries from config/environments/test.rb by fixing the underlying N+1 queries with proper eager loading.

The changes include:

  • Adding missing .includes
  • Making eager loading conditional when associations are only accessed in specific contexts
  • Decoupling single-record finders from collection-level includes to avoid AVOID eager loading warnings
  • Using conditional preloading for associations only needed for certain record types

Related issue: THREESCALE-9973


Changes by commit

1cf51db5f

Add conditional :service include to ApplicationsIndexPresenter (only when no service filter and multiservice) and add :service + user_account: [:admin_user] includes to Buyers::Applications::Bulk::BaseController.

Removes:

  • Cinstance :service

ec7a2790d

Add conditional :user_account include to ApplicationsIndexPresenter (only when no buyer context).

Removes:

  • Cinstance :user_account

f728eaf8a

Extend user_account include to user_account: [:admin_user] in ApplicationsIndexPresenter.

The view accesses account.admin_user via link_to_buyer_or_deleted.

Removes:

  • Account :admin_user

4d5cd6a3a

Add conditional bought_account_plan and bought_account_contract: [:plan] includes to Buyers::AccountsIndexPresenter (only when account_plans_size > 1).

Removes:

  • Account :bought_account_plan
  • Account :bought_account_contract

d48671d19

Add .includes(:user) to proxy configs collection query and decouple single-record finder to avoid AVOID eager loading warnings on show action.

Removes:

  • ProxyConfig :user

e5d3f9928

Add .includes(message: { sender: [:admin_user] }) to inbox controller and .includes(:sender) to trash controller.

  • Inbox uses MessageRecipient (sender accessed through Message)
  • Trash uses Message directly

Removes:

  • Message :sender

cf283f0c4

Add .includes({ buyer_account: [:admin_user] }, :provider_account) to Finance::Provider::InvoicesIndexPresenter and .includes(:buyer_account, :provider_account) to Provider::Admin::Account::InvoicesController.

Removes:

  • Invoice :buyer_account
  • Invoice :provider_account

ba9d0b49c

Use ActiveRecord::Associations::Preloader to conditionally preload :member_permissions only for member users in UsersIndexPresenter, avoiding AVOID eager loading warnings when all users are admins.

Removes:

  • User :member_permissions

@qltysh
Copy link
Copy Markdown

qltysh Bot commented May 21, 2026

❌ 3 blocking issues (4 total)

Tool Category Rule Count
reek Lint ApplicationsIndexPresenter#applications performs a nil-check 2
rubocop Lint Assignment Branch Condition size for applications is too high. [<2, 21, 5> 21.68/20] 1
qlty Structure Function with high complexity (count = 5): applications 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant