Skip to content

Commit

Permalink
Add some additional comments for context
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewelwell committed May 10, 2024
1 parent 9b05ff7 commit ac05461
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions api/edge_api/identities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,18 @@ def get_all_feature_states(
)
django_environment = Environment.objects.get(api_key=self.environment_api_key)

# since identity overrides are included in the document retrieved from dynamo,
# we only want to retrieve the environment default and (relevant) segment overrides
# from the ORM.
additional_filters = Q(identity__isnull=True) & (
Q(feature_segment__segment__id__in=segment_ids)
| Q(feature_segment__isnull=True)
)

feature_states: dict[str, FeatureState | FeatureStateModel] = (
get_environment_flags_dict(
environment=django_environment,
additional_filters=(
Q(identity__isnull=True)
& (
Q(feature_segment__segment__id__in=segment_ids)
| Q(feature_segment__isnull=True)
)
),
additional_filters=additional_filters,
additional_select_related_args=[
"feature",
"feature_segment",
Expand All @@ -105,10 +107,17 @@ def get_all_feature_states(
),
)
],
# since we only want to retrieve the highest priority feature state,
# we key off the feature name instead of the default
# (feature_id, segment_id, identity_id). This will give us only e.g.
# the highest priority matching segment override for a given feature.
key_function=lambda fs: fs.feature.name,
)
)

# Since the identity overrides are the highest priority, we can now iterate
# over the dictionary and replace any feature states with those that have
# an identity override, stored against the identity in dynamo.
identity_feature_states = self.feature_overrides
identity_feature_names = set()
for identity_feature_state in identity_feature_states:
Expand Down

0 comments on commit ac05461

Please sign in to comment.