Overview
AbTestingService iterates experiment.variants and issues a separate save() inside the loop (around src/ab-testing/ab-testing.service.ts:266 and :361), producing one write round-trip per variant. For an experiment with many variants this is a classic N+1 write pattern that multiplies latency and transaction overhead, and because the writes are not wrapped in a transaction a partial failure leaves the variant set inconsistent.
Specifications
Tasks:
- Collect the mutated variant entities and persist them with a single bulk
save(array) / insert call.
- Wrap the bulk write in a transaction so all variants commit or none do.
- Audit
statistical-analysis.service.ts for the same per-variant loop pattern.
- Add a test asserting the number of write queries is constant regardless of variant count.
Impacted Files:
src/ab-testing/ab-testing.service.ts
src/ab-testing/analysis/statistical-analysis.service.ts
Acceptance Criteria
- Saving N variants issues one bulk write, not N.
- The variant update is atomic.
- A test pins the query count.
Overview
AbTestingServiceiteratesexperiment.variantsand issues a separatesave()inside the loop (aroundsrc/ab-testing/ab-testing.service.ts:266and:361), producing one write round-trip per variant. For an experiment with many variants this is a classic N+1 write pattern that multiplies latency and transaction overhead, and because the writes are not wrapped in a transaction a partial failure leaves the variant set inconsistent.Specifications
Tasks:
save(array)/insertcall.statistical-analysis.service.tsfor the same per-variant loop pattern.Impacted Files:
src/ab-testing/ab-testing.service.tssrc/ab-testing/analysis/statistical-analysis.service.tsAcceptance Criteria