Skip to content

remove segments joins from assign path - #3300

Open
bcb37 wants to merge 1 commit into
devfrom
feature/remove-segment-joins-from-assign
Open

remove segments joins from assign path#3300
bcb37 wants to merge 1 commit into
devfrom
feature/remove-segment-joins-from-assign

Conversation

@bcb37

@bcb37 bcb37 commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@bcb37
bcb37 requested review from danoswaltCL and zackcl and a lite review from Copilot and removed request for danoswaltCL August 27, 2026 21:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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* and getValidExperimentsForContextAndDecisionPoint.
  • Added ExperimentRepository.getSegmentIdsForExperiments() to fetch only inclusion/exclusion segmentIds 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,
};
});
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.

2 participants