Skip to content

feat(Segment membership): Refresh membership counts on segment edit#7828

Merged
khvn26 merged 1 commit into
mainfrom
feat/segment-edit-membership-refresh
Jun 19, 2026
Merged

feat(Segment membership): Refresh membership counts on segment edit#7828
khvn26 merged 1 commit into
mainfrom
feat/segment-edit-membership-refresh

Conversation

@khvn26

@khvn26 khvn26 commented Jun 18, 2026

Copy link
Copy Markdown
Member

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Closes #7470.

In this PR, we wire the per-project segment membership count cache refresh into the segment edit paths. The daily backfill stays as the safety net for projects whose segments aren't edited.

A new enqueue_membership_refresh(project) service queues refresh_project_segment_counts for a project with a debounce to protect against rapid successive edits.

It's called from each path that creates or edits a canonical segment:

  • Creating a segment (SegmentSerializer.create)
  • Editing a segment (SegmentSerializer.update)
  • Cloning a segment (the clone viewset action)
  • Importing from LaunchDarkly (once after process_import_request completes)

Segment deletion is left to the daily backfill, which prunes stale count rows.

How did you test this code?

Added new tests:

  • Unit tests for enqueue_membership_refresh covering the flag gate, the per-project debounce, and that an enqueued refresh runs end to end.
  • Integration tests asserting each path triggers the refresh: create, update, and clone via the API, and the LaunchDarkly import.

Wire the per-project segment membership count refresh into the segment
create, update, clone and LaunchDarkly import paths via a new
`enqueue_membership_refresh` service, so edits refresh counts within
minutes instead of waiting for the daily backfill. The service debounces
per project and no-ops when the feature flag is off.

beep boop
@khvn26 khvn26 requested review from a team as code owners June 18, 2026 17:40
@khvn26 khvn26 requested review from emyller and removed request for a team June 18, 2026 17:40
@vercel

vercel Bot commented Jun 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Jun 18, 2026 5:40pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
flagsmith-frontend-preview Ignored Ignored Jun 18, 2026 5:40pm
flagsmith-frontend-staging Ignored Ignored Jun 18, 2026 5:40pm

Request Review

@github-actions github-actions Bot added api Issue related to the REST API docs Documentation updates feature New feature or request and removed docs Documentation updates labels Jun 18, 2026
@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-api-test:pr-7828 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-7828 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-e2e:pr-7828 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api:pr-7828 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-7828 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-7828 Finished ✅ Results

@khvn26 khvn26 changed the title feat(segments): Refresh membership counts on segment edit feat(Segment membership): Refresh membership counts on segment edit Jun 18, 2026
@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.58%. Comparing base (c4670cb) to head (5836e78).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7828   +/-   ##
=======================================
  Coverage   98.58%   98.58%           
=======================================
  Files        1465     1466    +1     
  Lines       56889    56974   +85     
=======================================
+ Hits        56082    56167   +85     
  Misses        807      807           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  42.1 seconds
commit  5836e78
info  🔄 Run: #17653 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  44.2 seconds
commit  5836e78
info  🔄 Run: #17653 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  3 passed

Details

stats  3 tests across 3 suites
duration  1 minute, 2 seconds
commit  5836e78
info  🔄 Run: #17653 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  3 passed

Details

stats  3 tests across 3 suites
duration  36.5 seconds
commit  5836e78
info  🔄 Run: #17653 (attempt 1)

@github-actions

Copy link
Copy Markdown
Contributor

Visual Regression

19 screenshots compared. See report for details.
View full report

@emyller emyller 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.

I'd love to see suggested improvements to tests, though none are blocking if you need to proceed.

Comment thread api/tests/integration/segments/test_segment_membership_refresh.py
Comment thread api/tests/unit/integrations/launch_darkly/test_services.py
Comment thread api/tests/unit/integrations/launch_darkly/test_services.py
@khvn26 khvn26 merged commit 1bdb7ca into main Jun 19, 2026
34 checks passed
@khvn26 khvn26 deleted the feat/segment-edit-membership-refresh branch June 19, 2026 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Segment-edit-triggered membership count refresh

2 participants