Skip to content

Commit eb7a909

Browse files
authored
move id list to cdn (#444)
moving default id list url to cdn, tested locally with gates that require id list
1 parent 30c8e03 commit eb7a909

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

statsig/http_worker.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,26 @@ def get_dcs_fallback(self, on_complete: Callable, since_time=0, log_on_exception
7373
on_complete(DataSource.STATSIG_NETWORK, None, None)
7474

7575
def get_id_lists(self, on_complete: Callable, log_on_exception=False, init_timeout=None):
76-
response = self._post_request(
77-
url=f"{self.__api_for_get_id_lists}get_id_lists",
78-
headers=None,
79-
payload={"statsigMetadata": self.__statsig_metadata},
80-
log_on_exception=log_on_exception,
81-
init_timeout=init_timeout,
82-
tag="get_id_lists",
83-
)
76+
response = None
77+
if self.__is_cdn_url(self.__api_for_get_id_lists):
78+
response = self.get_id_lists_fallback(on_complete, log_on_exception, init_timeout)
79+
else:
80+
response = self._post_request(
81+
url=f"{self.__api_for_get_id_lists}get_id_lists",
82+
headers=None,
83+
payload={"statsigMetadata": self.__statsig_metadata},
84+
log_on_exception=log_on_exception,
85+
init_timeout=init_timeout,
86+
tag="get_id_lists",
87+
)
8488
if response is not None and self._is_success_code(response.status_code):
8589
return on_complete(response.data, None)
8690
return on_complete(None, None)
8791

8892
def get_id_lists_fallback(self, on_complete: Callable, log_on_exception=False, init_timeout=None):
89-
response = self._post_request(
90-
url=f"{STATSIG_API}get_id_lists",
93+
response = self._get_request(
94+
url=f"{STATSIG_CDN}get_id_lists/{self.__sdk_key}.json",
9195
headers=None,
92-
payload={"statsigMetadata": self.__statsig_metadata},
9396
log_on_exception=log_on_exception,
9497
init_timeout=init_timeout,
9598
tag="get_id_lists",
@@ -358,7 +361,7 @@ def __configure_endpoints(self, options: StatsigOptions) -> None:
358361

359362
api_for_get_id_lists = (self.__get_proxy_address(options, NetworkEndpoint.GET_ID_LISTS)
360363
or options.api_for_get_id_lists
361-
or options.api or STATSIG_API)
364+
or options.api or STATSIG_CDN)
362365
if not api_for_get_id_lists.endswith("/"):
363366
api_for_get_id_lists += "/"
364367

@@ -371,3 +374,6 @@ def __configure_endpoints(self, options: StatsigOptions) -> None:
371374
self.__api_for_download_config_specs = api_for_download_config_specs
372375
self.__api_for_get_id_lists = api_for_get_id_lists
373376
self.__api_for_log_event = api_for_log_event
377+
378+
def __is_cdn_url(self, url: str) -> bool:
379+
return url.startswith(STATSIG_CDN)

statsig/statsig_network.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
DEFAULT_RULESET_SYNC_INTERVAL,
2020
StatsigOptions,
2121
STATSIG_CDN,
22-
STATSIG_API, ProxyConfig,
22+
ProxyConfig,
2323
)
2424
from .thread_util import spawn_background_thread
2525

@@ -211,8 +211,8 @@ def get_id_lists_fallback(
211211
NetworkEndpoint.GET_ID_LISTS
212212
)
213213
id_list_api_override = self.options.api_for_get_id_lists
214-
is_id_lists_proxy = id_list_api_override != STATSIG_API or (
215-
id_list_proxy and id_list_proxy.proxy_address != STATSIG_API)
214+
is_id_lists_proxy = id_list_api_override != STATSIG_CDN or (
215+
id_list_proxy and id_list_proxy.proxy_address != STATSIG_CDN)
216216
if is_id_lists_proxy:
217217
self.http_worker.get_id_lists_fallback(on_complete, log_on_exception, init_timeout)
218218

0 commit comments

Comments
 (0)