@@ -17,10 +17,11 @@ function sdkEndpointOverriden(settings: ISettings) {
17
17
* Factory of SplitChanges fetcher.
18
18
* SplitChanges fetcher is a wrapper around `splitChanges` API service that parses the response and handle errors.
19
19
*/
20
+ // @TODO breaking: drop support for Split Proxy below v5.10.0 and simplify the implementation
20
21
export function splitChangesFetcherFactory ( fetchSplitChanges : IFetchSplitChanges , settings : ISettings , storage : Pick < IStorageBase , 'splits' | 'rbSegments' > ) : ISplitChangesFetcher {
21
22
22
23
const PROXY_CHECK_INTERVAL_MILLIS = settings . core . key !== undefined ? PROXY_CHECK_INTERVAL_MILLIS_CS : PROXY_CHECK_INTERVAL_MILLIS_SS ;
23
- let _lastProxyCheckTimestamp : number | undefined ;
24
+ let lastProxyCheckTimestamp : number | undefined ;
24
25
25
26
return function splitChangesFetcher (
26
27
since : number ,
@@ -31,15 +32,16 @@ export function splitChangesFetcherFactory(fetchSplitChanges: IFetchSplitChanges
31
32
decorator ?: ( promise : Promise < IResponse > ) => Promise < IResponse >
32
33
) : Promise < ISplitChangesResponse > {
33
34
34
- if ( _lastProxyCheckTimestamp && ( Date . now ( ) - _lastProxyCheckTimestamp ) > PROXY_CHECK_INTERVAL_MILLIS ) {
35
+ // Recheck proxy
36
+ if ( lastProxyCheckTimestamp && ( Date . now ( ) - lastProxyCheckTimestamp ) > PROXY_CHECK_INTERVAL_MILLIS ) {
35
37
settings . sync . flagSpecVersion = FLAG_SPEC_VERSION ;
36
38
}
37
39
38
- let splitsPromise = fetchSplitChanges ( since , noCache , till , rbSince )
39
- // Handle proxy errors with spec 1.3
40
+ let splitsPromise = fetchSplitChanges ( since , noCache , till , settings . sync . flagSpecVersion === FLAG_SPEC_VERSION ? rbSince : undefined )
41
+ // Handle proxy error with spec 1.3
40
42
. catch ( ( err ) => {
41
43
if ( err . statusCode === 400 && sdkEndpointOverriden ( settings ) && settings . sync . flagSpecVersion === FLAG_SPEC_VERSION ) {
42
- _lastProxyCheckTimestamp = Date . now ( ) ;
44
+ lastProxyCheckTimestamp = Date . now ( ) ;
43
45
settings . sync . flagSpecVersion = '1.2' ; // fallback to 1.2 spec
44
46
return fetchSplitChanges ( since , noCache , till ) ; // retry request without rbSince
45
47
}
@@ -63,10 +65,10 @@ export function splitChangesFetcherFactory(fetchSplitChanges: IFetchSplitChanges
63
65
}
64
66
65
67
// Proxy recovery
66
- if ( _lastProxyCheckTimestamp ) {
67
- _lastProxyCheckTimestamp = undefined ;
68
+ if ( lastProxyCheckTimestamp ) {
69
+ lastProxyCheckTimestamp = undefined ;
68
70
return Promise . all ( [ storage . splits . clear ( ) , storage . rbSegments . clear ( ) ] )
69
- . then ( ( ) => splitChangesFetcher ( - 1 , undefined , undefined , - 1 ) ) ;
71
+ . then ( ( ) => splitChangesFetcher ( storage . splits . getChangeNumber ( ) as number , undefined , undefined , storage . rbSegments . getChangeNumber ( ) as number ) ) ;
70
72
}
71
73
72
74
return data ;
0 commit comments