Skip to content

feature flag optimizations part one#3145

Merged
danoswaltCL merged 4 commits into
devfrom
fix/ff-service-get-keys-optimizations
Jun 3, 2026
Merged

feature flag optimizations part one#3145
danoswaltCL merged 4 commits into
devfrom
fix/ff-service-get-keys-optimizations

Conversation

@danoswaltCL
Copy link
Copy Markdown
Collaborator

@danoswaltCL danoswaltCL commented Jun 2, 2026

handles 1a, 1b, and 4 from the research spike plan that claude and I spun up #3143

  • Removes global exclude logic from getKeys() (if we can't do that, then we'll need to cache the global exclude lists, because it isn't happening currently so gets called every time... not a problem current as clc and mathia-student-ui don't have global exclude lists currently, but if someone added a big one today, it would cause problems)

  • Guards against include-list data being used in segment lookups when INCLUDE_ALL (this is one part of a two part fix in another pr)

  • Fixes issues in exposure save:

    • wasn't actually fire-and-forget because the transaction is awaited
    • was doing a full SELECT on every call with .save because of how typeorm treats full object as param vs an id, however:
    • ignore on conflict makes that work the way we'd actually want, which is to do a blind insert and bail if it exists without erroring

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 targets backend feature-flag performance by streamlining FeatureFlagService.getKeys() execution: it removes a per-request global-exclusion check, prevents irrelevant inclusion-segment data from being used for INCLUDE_ALL flags, and makes exposure recording a true fire-and-forget bulk insert with conflict ignore.

Changes:

  • Removed global exclusion logic from getKeys() to avoid repeated expensive checks per request.
  • Adjusted segment resolution inputs to ignore inclusion segments when filterMode === INCLUDE_ALL.
  • Reworked exposure persistence to use a repository bulk insert with orIgnore() and to avoid awaiting a transaction; added unit tests for the new behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
packages/backend/src/api/services/FeatureFlagService.ts Removes global exclusion check, guards inclusion segment IDs for INCLUDE_ALL, and switches exposure recording to fire-and-forget via repository insert.
packages/backend/src/api/repositories/FeatureFlagExposureRepository.ts Adds recordExposureIfNotExists() bulk insert using orIgnore() to avoid duplicate-write overhead.
packages/backend/test/unit/services/FeatureFlagService.test.ts Adds unit coverage for removed global exclusion call, exposure recording behavior, and segment handling by filterMode.
packages/backend/test/unit/repositories/FeatureFlagExposureRepository.test.ts Adds unit coverage asserting the repository insert path uses orIgnore() and correct values.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/backend/src/api/services/FeatureFlagService.ts Outdated
danoswaltCL and others added 3 commits June 2, 2026 21:17
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@danoswaltCL danoswaltCL merged commit 40f7b8e into dev Jun 3, 2026
5 checks passed
@danoswaltCL danoswaltCL deleted the fix/ff-service-get-keys-optimizations branch June 3, 2026 21:00
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.

3 participants