MCPcopy Create free account
hub / github.com/Flagsmith/flagsmith / _include_users_to_segment

Function _include_users_to_segment

api/integrations/launch_darkly/services.py:956–996  ·  view source on GitHub ↗
(
    import_request: LaunchDarklyImportRequest,
    segment: Segment,
    users: list[str],
    negate: bool,
)

Source from the content-addressed store, hash-verified

954
955
956def _include_users_to_segment(
957 import_request: LaunchDarklyImportRequest,
958 segment: Segment,
959 users: list[str],
960 negate: bool,
961) -> None:
962 if len(users) == 0:
963 return
964
965 # Find the parent rule of the segment.
966 parent_rule, _ = SegmentRule.objects.get_or_create(
967 segment=segment, type=SegmentRule.ALL_RULE
968 )
969
970 # Create a condition to match against those identities via "key" trait.
971 for identities_string in iter_chunked_concat(
972 values=users,
973 delimiter=",",
974 max_len=settings.SEGMENT_CONDITION_VALUE_LIMIT,
975 ):
976 if len(identities_string) > settings.SEGMENT_CONDITION_VALUE_LIMIT:
977 _log_error(
978 import_request=import_request,
979 error_message=(
980 f"Targeting key '{truncate(identities_string)}' exceeds the limit of"
981 f" {settings.SEGMENT_CONDITION_VALUE_LIMIT} characters, "
982 f"skipping for segment '{segment.name}'"
983 ),
984 )
985 continue
986 included_rule = SegmentRule.objects.create(
987 rule=parent_rule,
988 type=SegmentRule.NONE_RULE if negate else SegmentRule.ANY_RULE,
989 )
990 Condition.objects.update_or_create(
991 rule=included_rule,
992 property="key",
993 value=identities_string,
994 operator=constants.IN,
995 created_with_segment=True,
996 )
997
998
999def _create_segments_from_ld(

Callers 1

_create_segments_from_ldFunction · 0.85

Calls 4

iter_chunked_concatFunction · 0.90
truncateFunction · 0.90
_log_errorFunction · 0.85
createMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…