-
Notifications
You must be signed in to change notification settings - Fork 429
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
feat: Rely on Flagsmith Engine for segment evaluation #2865
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Uffizzi Preview |
api/segments/models.py
Outdated
segment_model = map_segment_to_engine(self) | ||
identity_model = map_identity_to_engine(identity) | ||
trait_models = map_traits_to_trait_models(traits) if traits else None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My concern here is that it's a bit hidden as to what additional database interactions are happening. I think, to plugin the engine, we need to do it much earlier in the flow and use e.g. engine.get_identity_feature_states
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
additional database interactions
These are well covered by the currently failing assertNumQueries
assertion in test_get_segments
. IMO if we manage to keep the same amount (or less) by prefetching the data, we're good.
do it much earlier in the flow and use e.g. engine.get_identity_feature_states.
I'll think of it but my primary focus here is to replace the segment matching logic first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO if we manage to keep the same amount (or less) by prefetching the data, we're good.
Yep, fair enough.
403c5dd
to
5a908b0
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2865 +/- ##
==========================================
+ Coverage 95.60% 95.75% +0.15%
==========================================
Files 1022 1021 -1
Lines 29854 29676 -178
==========================================
- Hits 28541 28417 -124
+ Misses 1313 1259 -54 ☔ View full report in Codecov by Sentry. |
3bd2564
to
3b11d53
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved with one minor comment. So goo d being able to delete all this code. I'm assuming as well that, since there are no test failures, we haven't had to introduce any new queries here.
@@ -370,7 +370,7 @@ def test_identities_endpoint_returns_traits(self, mock_amplitude_wrapper): | |||
trait = Trait.objects.create( | |||
identity=self.identity, | |||
trait_key="trait_key", | |||
value_type="STRING", | |||
value_type=STRING, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tend to think this is because those tests were wrong (and we were lucky that the default type is string) but it's worth noting that this is a slight change "STRING"
-> "unicode"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. The engine mapper relies on Trait
's trait_value
property which doesn't employ the default string fallback.
Thanks for submitting a PR! Please check the boxes below:
pre-commit
to check lintingChanges
This PR removes legacy code responsible for segment rule evaluation and replaces it with Flagsmith engine implementation.
How did you test this code?