Skip to content

refactor: only clone latest feature states #5743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jul 15, 2025

Conversation

matthewelwell
Copy link
Contributor

@matthewelwell matthewelwell commented Jul 10, 2025

Changes

This PR changes the behaviour when cloning an environment. Previously, the logic would create a clone of all feature states, including old versions, feature states associated with uncommitted change requests, etc. This PR updates the logic to only clone the latest feature states, and mark them as live from the moment the environment is created.

This does change the user experience, but only really for those using v2 versioning (which is currently very few customers), in that they will no longer see a history of changes in the new environment. In my opinion, it was odd behaviour to show the history from another environment in the new environment anyway, so I think this is an improvement.

Refactor environment clone functionality to only clone the latest feature states. This will optimise the logic to speed it up reduce the impact of cloning environments on the database. I've also included some additional DB optimisations using select and prefetch related where necessary.

Note that this also fixes a bug in the logic for enabling versioning on new environments which existed because we were previously using the enable_v2_versioning task to create the versions, but this expected the input environment to not have versioning enabled.

How did you test this code?

Existing tests should cover the refactor. Updated an existing test with better assertions to verify the bug fix, and new logic.

Copy link

vercel bot commented Jul 10, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs ⬜️ Ignored (Inspect) Visit Preview Jul 11, 2025 7:55am
flagsmith-frontend-preview ⬜️ Ignored (Inspect) Visit Preview Jul 11, 2025 7:55am
flagsmith-frontend-staging ⬜️ Ignored (Inspect) Visit Preview Jul 11, 2025 7:55am

@github-actions github-actions bot added api Issue related to the REST API refactor labels Jul 10, 2025
Copy link

codecov bot commented Jul 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.77%. Comparing base (bca7ed1) to head (37703d3).
Report is 8 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5743   +/-   ##
=======================================
  Coverage   97.77%   97.77%           
=======================================
  Files        1255     1255           
  Lines       44357    44359    +2     
=======================================
+ Hits        43371    43373    +2     
  Misses        986      986           

☔ View full report in Codecov by Sentry.
📢 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.

@matthewelwell matthewelwell marked this pull request as ready for review July 10, 2025 16:20
@matthewelwell matthewelwell requested a review from a team as a code owner July 10, 2025 16:20
@matthewelwell matthewelwell requested review from Zaimwa9 and khvn26 and removed request for a team July 10, 2025 16:20
Copy link
Contributor

github-actions bot commented Jul 10, 2025

Docker builds report

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

Copy link
Member

@khvn26 khvn26 left a comment

Choose a reason for hiding this comment

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

Two minor suggestions. The logic looks fine to me.

@matthewelwell matthewelwell requested a review from khvn26 July 11, 2025 07:34
@matthewelwell matthewelwell merged commit 4f703a1 into main Jul 15, 2025
29 of 31 checks passed
@matthewelwell matthewelwell deleted the refactor/only-clone-latest-feature-states branch July 15, 2025 07:52
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 refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants