@@ -42,7 +42,7 @@ def __init__(self, split_api, split_storage):
4242 _ON_DEMAND_FETCH_BACKOFF_BASE ,
4343 _ON_DEMAND_FETCH_BACKOFF_MAX_WAIT )
4444
45- def _fetch_until (self , fetch_options , till = None , segment_sync = None ):
45+ def _fetch_until (self , fetch_options , till = None ):
4646 """
4747 Hit endpoint, update storage and return when since==till.
4848
@@ -55,7 +55,7 @@ def _fetch_until(self, fetch_options, till=None, segment_sync=None):
5555 :return: last change number
5656 :rtype: int
5757 """
58- segment_list = []
58+ segment_list = set ()
5959 while True : # Fetch until since==till
6060 change_number = self ._split_storage .get_change_number ()
6161 if change_number is None :
@@ -70,23 +70,19 @@ def _fetch_until(self, fetch_options, till=None, segment_sync=None):
7070 _LOGGER .error ('Exception raised while fetching splits' )
7171 _LOGGER .debug ('Exception information: ' , exc_info = True )
7272 raise exc
73-
73+
7474 for split in split_changes .get ('splits' , []):
7575 if split ['status' ] == splits .Status .ACTIVE .value :
76- self ._split_storage .put (splits .from_raw (split ))
76+ parsed = splits .from_raw (split )
77+ self ._split_storage .put (parsed )
78+ segment_list .update (set (parsed .get_segment_names ()))
7779 else :
7880 self ._split_storage .remove (split ['name' ])
79- for segment in self ._split_storage .get_segment_names ():
80- _LOGGER .debug ('Found segment: %s' , segment )
81- if not segment_sync .segment_exist_in_storage (segment ):
82- _LOGGER .debug ('Segment %s does not exist, syncing.' , segment )
83- segment_list .append (segment )
84-
8581 self ._split_storage .set_change_number (split_changes ['till' ])
8682 if split_changes ['till' ] == split_changes ['since' ]:
8783 return split_changes ['till' ], segment_list
8884
89- def _attempt_split_sync (self , fetch_options , till = None , segment_sync = None ):
85+ def _attempt_split_sync (self , fetch_options , till = None ):
9086 """
9187 Hit endpoint, update storage and return True if sync is complete.
9288
@@ -103,15 +99,15 @@ def _attempt_split_sync(self, fetch_options, till=None, segment_sync=None):
10399 remaining_attempts = _ON_DEMAND_FETCH_BACKOFF_MAX_RETRIES
104100 while True :
105101 remaining_attempts -= 1
106- change_number , segment_list = self ._fetch_until (fetch_options , till , segment_sync )
102+ change_number , segment_list = self ._fetch_until (fetch_options , till )
107103 if till is None or till <= change_number :
108104 return True , remaining_attempts , change_number , segment_list
109105 elif remaining_attempts <= 0 :
110106 return False , remaining_attempts , change_number , segment_list
111107 how_long = self ._backoff .get ()
112108 time .sleep (how_long )
113109
114- def synchronize_splits (self , till = None , segment_sync = None ):
110+ def synchronize_splits (self , till = None ):
115111 """
116112 Hit endpoint, update storage and return True if sync is complete.
117113
@@ -120,13 +116,13 @@ def synchronize_splits(self, till=None, segment_sync=None):
120116 """
121117 fetch_options = FetchOptions (True ) # Set Cache-Control to no-cache
122118 successful_sync , remaining_attempts , change_number , segment_list = self ._attempt_split_sync (fetch_options ,
123- till , segment_sync )
119+ till )
124120 attempts = _ON_DEMAND_FETCH_BACKOFF_MAX_RETRIES - remaining_attempts
125121 if successful_sync : # succedeed sync
126122 _LOGGER .debug ('Refresh completed in %d attempts.' , attempts )
127123 return segment_list
128124 with_cdn_bypass = FetchOptions (True , change_number ) # Set flag for bypassing CDN
129- without_cdn_successful_sync , remaining_attempts , change_number , segment_list = self ._attempt_split_sync (with_cdn_bypass , till , segment_sync )
125+ without_cdn_successful_sync , remaining_attempts , change_number , segment_list = self ._attempt_split_sync (with_cdn_bypass , till )
130126 without_cdn_attempts = _ON_DEMAND_FETCH_BACKOFF_MAX_RETRIES - remaining_attempts
131127 if without_cdn_successful_sync :
132128 _LOGGER .debug ('Refresh completed bypassing the CDN in %d attempts.' ,
0 commit comments