Skip to content

Commit 4c979f7

Browse files
Removed the migration logic for the old format of MySegments keys in LocalStorage introduced in JavaScript SDK v10.17.3
1 parent e1a49f5 commit 4c979f7

File tree

4 files changed

+2
-68
lines changed

4 files changed

+2
-68
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Removed support for MY_SEGMENTS_UPDATE and MY_SEGMENTS_UPDATE_V2 notification types, as they are replaced by MEMBERSHIPS_MS_UPDATE and MEMBERSHIPS_LS_UPDATE notification types.
99
- Removed the deprecated `GOOGLE_ANALYTICS_TO_SPLIT` and `SPLIT_TO_GOOGLE_ANALYTICS` integrations.
1010
- Removed internal ponyfills for `Map`, `Set` and `Array.from` global objects, dropping support for IE and other outdated browsers. The SDK now requires the runtime environment to support these features natively or to provide a polyfill.
11+
- Removed the migration logic for the old format of MySegments keys in LocalStorage introduced in JavaScript SDK v10.17.3.
1112

1213
1.17.0 (September 6, 2024)
1314
- Added `sync.requestOptions.getHeaderOverrides` configuration option to enhance SDK HTTP request Headers for Authorization Frameworks.

src/storages/KeyBuilderCS.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { KeyBuilder } from './KeyBuilder';
44
export interface MySegmentsKeyBuilder {
55
buildSegmentNameKey(segmentName: string): string;
66
extractSegmentName(builtSegmentKeyName: string): string | undefined;
7-
extractOldSegmentKey(builtSegmentKeyName: string): string | undefined;
87
buildTillKey(): string;
98
}
109

@@ -33,14 +32,6 @@ export class KeyBuilderCS extends KeyBuilder implements MySegmentsKeyBuilder {
3332
return builtSegmentKeyName.substr(prefix.length);
3433
}
3534

36-
// @BREAKING: The key used to start with the matching key instead of the prefix, this was changed on version 10.17.3
37-
extractOldSegmentKey(builtSegmentKeyName: string) {
38-
const prefix = `${this.matchingKey}.${this.prefix}.segment.`;
39-
40-
if (startsWith(builtSegmentKeyName, prefix))
41-
return builtSegmentKeyName.substr(prefix.length);
42-
}
43-
4435
buildLastUpdatedKey() {
4536
return `${this.prefix}.splits.lastUpdated`;
4637
}
@@ -66,10 +57,6 @@ export function myLargeSegmentsKeyBuilder(prefix: string, matchingKey: string):
6657
if (startsWith(builtSegmentKeyName, p)) return builtSegmentKeyName.substr(p.length);
6758
},
6859

69-
extractOldSegmentKey() {
70-
return undefined;
71-
},
72-
7360
buildTillKey() {
7461
return `${prefix}.${matchingKey}.largeSegments.till`;
7562
}

src/storages/inLocalStorage/MySegmentsCacheInLocal.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,7 @@ export class MySegmentsCacheInLocal extends AbstractSegmentsCacheSync {
5151
return Object.keys(localStorage).reduce((accum, key) => {
5252
let segmentName = this.keys.extractSegmentName(key);
5353

54-
if (segmentName) {
55-
accum.push(segmentName);
56-
} else {
57-
// @TODO @BREAKING: This is only to clean up "old" keys. Remove this whole else code block
58-
segmentName = this.keys.extractOldSegmentKey(key);
59-
60-
if (segmentName) { // this was an old segment key, let's clean up.
61-
const newSegmentKey = this.keys.buildSegmentNameKey(segmentName);
62-
try {
63-
// If the new format key is not there, create it.
64-
if (!localStorage.getItem(newSegmentKey)) {
65-
localStorage.setItem(newSegmentKey, DEFINED);
66-
// we are migrating a segment, let's track it.
67-
accum.push(segmentName);
68-
}
69-
localStorage.removeItem(key); // we migrated the current key, let's delete it.
70-
} catch (e) {
71-
this.log.error(e);
72-
}
73-
}
74-
}
54+
if (segmentName) accum.push(segmentName);
7555

7656
return accum;
7757
}, [] as string[]);

src/storages/inLocalStorage/__tests__/MySegmentsCacheInLocal.spec.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -34,37 +34,3 @@ test('SEGMENT CACHE / in LocalStorage', () => {
3434
expect(localStorage.getItem('SPLITIO.user.largeSegment.mocked-segment-2')).toBe('1');
3535
expect(localStorage.getItem('SPLITIO.user.largeSegment.mocked-segment')).toBe(null);
3636
});
37-
38-
// @BREAKING: REMOVE when removing this backwards compatibility.
39-
test('SEGMENT CACHE / in LocalStorage migration for mysegments keys', () => {
40-
41-
const keys = new KeyBuilderCS('LS_BC_test.SPLITIO', 'test_nico');
42-
const cache = new MySegmentsCacheInLocal(loggerMock, keys);
43-
44-
const oldKey1 = 'test_nico.LS_BC_test.SPLITIO.segment.segment1';
45-
const oldKey2 = 'test_nico.LS_BC_test.SPLITIO.segment.segment2';
46-
const newKey1 = keys.buildSegmentNameKey('segment1');
47-
const newKey2 = keys.buildSegmentNameKey('segment2');
48-
49-
cache.clear(); // cleanup before starting.
50-
51-
// Not adding a full suite for LS keys now, testing here
52-
expect(oldKey1).toBe(`test_nico.${keys.prefix}.segment.segment1`);
53-
expect('segment1').toBe(keys.extractOldSegmentKey(oldKey1));
54-
55-
// add two segments, one we don't want to send on reset, should only be cleared, other one will be migrated.
56-
localStorage.setItem(oldKey1, '1');
57-
localStorage.setItem(oldKey2, '1');
58-
expect(localStorage.getItem(newKey1)).toBe(null); // control assertion
59-
60-
cache.resetSegments({ k: [{ n: 'segment1' }] });
61-
62-
expect(localStorage.getItem(newKey1)).toBe('1'); // The segment key for segment1, as is part of the new list, should be migrated.
63-
expect(localStorage.getItem(newKey2)).toBe(null); // The segment key for segment2 should not be migrated.
64-
expect(localStorage.getItem(oldKey1)).toBe(null); // Old keys are removed.
65-
expect(localStorage.getItem(oldKey2)).toBe(null); // Old keys are removed.
66-
67-
cache.clear();
68-
expect(cache.getRegisteredSegments()).toEqual([]);
69-
expect(cache.getChangeNumber()).toBe(-1);
70-
});

0 commit comments

Comments
 (0)