Loading
Add Additional Preloads to RedactionService
What does this MR do and why?
Adds missing eager-load associations to both CE and EE.
DeclarativePolicy conditions access :organization, :saml_provider, :namespace, :assignees, :author, and :system_note_metadata during Ability.allowed? checks, but these were not being eagerly loaded. This caused N+1 lazy-load queries per resource in batch authorization.
This is MR 3 of 6 in the redaction scalability series. See orbit/knowledge-graph#348 for the full plan.
How to set up and validate locally
git checkout michaelangeloio/redaction-preloads
bundle exec rails runner tmp/profile_redaction_queries.rb
See the profiling script and full results in the MR comments below.
Before (master)
PER-TYPE QUERY PROFILE (cold caches, 215 resources)
Type Count Queries
-----------------------------------
project 8 11
group 7 16
issue 50 63
note 50 311
work_item 50 14
milestone 50 4
-----------------------------------
TOTAL 419
MIXED BATCH: 430
After (this MR)
PER-TYPE QUERY PROFILE (cold caches, 215 resources)
Type Count Queries
-----------------------------------
project 8 12
group 7 10
issue 50 17
note 50 42
work_item 50 16
milestone 50 6
-----------------------------------
TOTAL 103
MIXED BATCH: 118
Summary
| Metric | Before | After | Reduction |
|---|---|---|---|
| Mixed batch queries | 430 | 118 | 72% |
system_note_metadata |
50 (N+1) | 1 (batch) | 98% |
licenses |
217 | 55 | 75% |
saml_providers |
14 | 8 | 43% |
References
- Part of: orbit/knowledge-graph#348 (Improve Redaction / Auth Scalability)
- Research session:
764e8f8e(profiled 348 queries for 100 projects on postgres.ai)
Edited by Michael Angelo Rivera