remove segments joins from assign path - #3300
Open
bcb37 wants to merge 1 commit into
Open
Conversation
bcb37
requested review from
danoswaltCL and
zackcl
and
a lite review from Copilot
and removed request for
danoswaltCL
August 27, 2026 21:29
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces database work on the /assign experiment read path by removing eager inclusion/exclusion segment joins from the “valid experiments” repository queries, and instead fetching only segment IDs lazily when the experiment_precomputed_segment row is missing and an on-the-fly segment resolution fallback is required.
Changes:
- Removed inclusion/exclusion segment joins from
ExperimentRepository.getValidExperiments*andgetValidExperimentsForContextAndDecisionPoint. - Added
ExperimentRepository.getSegmentIdsForExperiments()to fetch only inclusion/exclusionsegmentIds for a scoped set of experiment IDs. - Updated assignment-path logic and unit tests to use the new lazy segment-id lookup, including mock fixtures.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/backend/src/api/services/ExperimentAssignmentService.ts | Switches segment resolution to a lazy, scoped lookup for experiments missing precomputed rows. |
| packages/backend/src/api/repositories/ExperimentRepository.ts | Removes eager segment joins from “valid experiments” queries and adds a lightweight segment-id query API. |
| packages/backend/test/unit/repositories/ExperimentRepository.test.ts | Updates expectations for reduced joins/queries and adds coverage for getSegmentIdsForExperiments. |
| packages/backend/test/unit/services/ExperimentAssignmentService.test.ts | Stubs the new repository method so existing assignment tests keep exercising fallback resolution. |
| packages/backend/test/unit/mockdata/raw.ts | Adds segmentId fields to inclusion/exclusion junction fixtures to match runtime expectations. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+2371
to
+2386
| const missingSegmentIdData = await this.experimentRepository.getSegmentIdsForExperiments(missingExpIds); | ||
| const missingSegmentObj: EntitySegmentResolutionInput = {}; | ||
| missingExpIds.forEach((id) => (missingSegmentObj[id] = segmentObj[id])); | ||
| missingExpIds.forEach((id) => { | ||
| const segmentIdData = missingSegmentIdData.find((data) => data.id === id); | ||
| const includeIds = | ||
| segmentIdData?.experimentSegmentInclusion?.map((segmentInclusion) => segmentInclusion.segmentId) || []; | ||
| const excludeIds = | ||
| segmentIdData?.experimentSegmentExclusion?.map((segmentExclusion) => segmentExclusion.segmentId) || []; | ||
| missingSegmentObj[id] = { | ||
| segmentIdsQueue: [...includeIds, ...excludeIds], | ||
| currentIncludedSegmentIds: includeIds, | ||
| currentExcludedSegmentIds: excludeIds, | ||
| allIncludedSegmentIds: includeIds, | ||
| allExcludedSegmentIds: excludeIds, | ||
| }; | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.