Skip to content

Commit c8ace12

Browse files
authored
Merge pull request #211 from launchdarkly/eb/sc-181822/preprocess-targets
store flag/segment target lists as sets
2 parents 404dea2 + 62c81f4 commit c8ace12

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

ldclient/impl/evaluator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ def _bucketable_string_value(u_value) -> Optional[str]:
423423

424424
return None
425425

426-
def _context_key_is_in_target_list(context: Context, context_kind: Optional[str], keys: Optional[List[str]]) -> bool:
426+
def _context_key_is_in_target_list(context: Context, context_kind: Optional[str], keys: Set[str]) -> bool:
427427
if keys is None or len(keys) == 0:
428428
return False
429429
match_context = context.get_individual_context(context_kind or Context.DEFAULT_KIND)

ldclient/impl/model/feature_flag.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, List, Optional
1+
from typing import Any, List, Optional, Set
22

33
from ldclient.impl.model.clause import Clause
44
from ldclient.impl.model.entity import *
@@ -27,7 +27,7 @@ class Target:
2727
def __init__(self, data: dict):
2828
self._context_kind = opt_str(data, 'contextKind')
2929
self._variation = req_int(data, 'variation')
30-
self._values = req_str_list(data, 'values')
30+
self._values = set(req_str_list(data, 'values'))
3131

3232
@property
3333
def context_kind(self) -> Optional[str]:
@@ -38,7 +38,7 @@ def variation(self) -> int:
3838
return self._variation
3939

4040
@property
41-
def values(self) -> List[str]:
41+
def values(self) -> Set[str]:
4242
return self._values
4343

4444

ldclient/impl/model/segment.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, List, Optional
1+
from typing import Any, List, Optional, Set
22

33
from ldclient.impl.model.attribute_ref import AttributeRef, opt_attr_ref_with_opt_context_kind
44
from ldclient.impl.model.clause import Clause
@@ -10,14 +10,14 @@ class SegmentTarget:
1010

1111
def __init__(self, data: dict, logger = None):
1212
self._context_kind = opt_str(data, 'contextKind')
13-
self._values = req_str_list(data, 'values')
13+
self._values = set(req_str_list(data, 'values'))
1414

1515
@property
1616
def context_kind(self) -> Optional[str]:
1717
return self._context_kind
1818

1919
@property
20-
def values(self) -> List[str]:
20+
def values(self) -> Set[str]:
2121
return self._values
2222

2323

@@ -63,8 +63,8 @@ def __init__(self, data: dict):
6363
self._deleted = opt_bool(data, 'deleted')
6464
if self._deleted:
6565
return
66-
self._included = opt_str_list(data, 'included')
67-
self._excluded = opt_str_list(data, 'excluded')
66+
self._included = set(opt_str_list(data, 'included'))
67+
self._excluded = set(opt_str_list(data, 'excluded'))
6868
self._included_contexts = list(SegmentTarget(item) for item in opt_dict_list(data, 'includedContexts'))
6969
self._excluded_contexts = list(SegmentTarget(item) for item in opt_dict_list(data, 'excludedContexts'))
7070
self._rules = list(SegmentRule(item) for item in opt_dict_list(data, 'rules'))
@@ -86,11 +86,11 @@ def deleted(self) -> bool:
8686
return self._deleted
8787

8888
@property
89-
def included(self) -> List[str]:
89+
def included(self) -> Set[str]:
9090
return self._included
9191

9292
@property
93-
def excluded(self) -> List[str]:
93+
def excluded(self) -> Set[str]:
9494
return self._excluded
9595

9696
@property

0 commit comments

Comments
 (0)