Skip to content

Commit 8429d40

Browse files
Implementation fixes
1 parent 2d1628d commit 8429d40

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/sync/polling/fetchers/splitChangesFetcher.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ function sdkEndpointOverriden(settings: ISettings) {
1717
* Factory of SplitChanges fetcher.
1818
* SplitChanges fetcher is a wrapper around `splitChanges` API service that parses the response and handle errors.
1919
*/
20+
// @TODO breaking: drop support for Split Proxy below v5.10.0 and simplify the implementation
2021
export function splitChangesFetcherFactory(fetchSplitChanges: IFetchSplitChanges, settings: ISettings, storage: Pick<IStorageBase, 'splits' | 'rbSegments'>): ISplitChangesFetcher {
2122

2223
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;
2425

2526
return function splitChangesFetcher(
2627
since: number,
@@ -31,15 +32,16 @@ export function splitChangesFetcherFactory(fetchSplitChanges: IFetchSplitChanges
3132
decorator?: (promise: Promise<IResponse>) => Promise<IResponse>
3233
): Promise<ISplitChangesResponse> {
3334

34-
if (_lastProxyCheckTimestamp && (Date.now() - _lastProxyCheckTimestamp) > PROXY_CHECK_INTERVAL_MILLIS) {
35+
// Recheck proxy
36+
if (lastProxyCheckTimestamp && (Date.now() - lastProxyCheckTimestamp) > PROXY_CHECK_INTERVAL_MILLIS) {
3537
settings.sync.flagSpecVersion = FLAG_SPEC_VERSION;
3638
}
3739

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
4042
.catch((err) => {
4143
if (err.statusCode === 400 && sdkEndpointOverriden(settings) && settings.sync.flagSpecVersion === FLAG_SPEC_VERSION) {
42-
_lastProxyCheckTimestamp = Date.now();
44+
lastProxyCheckTimestamp = Date.now();
4345
settings.sync.flagSpecVersion = '1.2'; // fallback to 1.2 spec
4446
return fetchSplitChanges(since, noCache, till); // retry request without rbSince
4547
}
@@ -63,10 +65,10 @@ export function splitChangesFetcherFactory(fetchSplitChanges: IFetchSplitChanges
6365
}
6466

6567
// Proxy recovery
66-
if (_lastProxyCheckTimestamp) {
67-
_lastProxyCheckTimestamp = undefined;
68+
if (lastProxyCheckTimestamp) {
69+
lastProxyCheckTimestamp = undefined;
6870
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));
7072
}
7173

7274
return data;

0 commit comments

Comments
 (0)