Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: first revision of delta api #8967

Merged
merged 30 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
500f9df
experimental: client feature toggle cache
sjaanus Dec 2, 2024
f538eb7
Update
sjaanus Dec 2, 2024
c9c59c1
Merge branch 'main' into client-cache
sighphyre Dec 3, 2024
74bc4bd
Update
sjaanus Dec 3, 2024
69525f5
Add to service
sjaanus Dec 3, 2024
79f98a1
Add to service
sjaanus Dec 3, 2024
88157ab
wip: basic cache and feature
sighphyre Dec 3, 2024
4b5cd76
chore: clean up some cruft
sighphyre Dec 3, 2024
208aa58
wip: clean up the revision calculation, needs some more testing
sighphyre Dec 3, 2024
7adc24f
fix: mount delta endpoint before catch all endpoint for features
sighphyre Dec 3, 2024
6aba8c5
fix: make promises resolve, add some temp debug
sighphyre Dec 3, 2024
ac731c3
chore: re-enable polling, trim some debug
sighphyre Dec 3, 2024
1909b17
chore: rename refactor of revision calculation
sighphyre Dec 3, 2024
f8acd2f
chore: extend tests
sighphyre Dec 3, 2024
0e20443
chore: update type for client features, the schema is not the correct…
sighphyre Dec 4, 2024
73ebbed
wip: add a way to retrieve a set of toggles from the db
sighphyre Dec 4, 2024
6da072a
chore: clean ups, rework some methods
sighphyre Dec 4, 2024
c385161
Fix base cache population
sjaanus Dec 4, 2024
0a99dcb
fix: handle gte revisions with a 304
sighphyre Dec 4, 2024
00dc25f
Fix base cache population
sjaanus Dec 4, 2024
8bb151d
fix: call environment correctly when loading features
sighphyre Dec 4, 2024
fe821a6
Fix
sjaanus Dec 4, 2024
b4c725b
Merge branch 'client-cache' of https://github.com/Unleash/unleash int…
sjaanus Dec 4, 2024
a6447c8
feat: data structure for revision lengths
FredrikOseberg Dec 6, 2024
9eb2394
fix: if you provide an etag not present, return the full updates
FredrikOseberg Dec 6, 2024
05e04ab
fix: no etag
FredrikOseberg Dec 6, 2024
68e74a1
fix: comment
FredrikOseberg Dec 6, 2024
8d2181e
Merge branch 'main' into client-cache
sjaanus Dec 12, 2024
6b077f1
Fix
sjaanus Dec 12, 2024
bed686f
Fix
sjaanus Dec 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
import { calculateRequiredClientRevision } from './client-feature-toggle-cache';

const mockAdd = (params): any => {
const base = {
name: 'feature',
project: 'default',
stale: false,
type: 'release',
enabled: true,
strategies: [],
variants: [],
description: 'A feature',
impressionData: [],
dependencies: [],
};
return { ...base, ...params };
};

test('compresses multiple revisions to a single update', () => {
const revisionList = [
{
revisionId: 1,
updated: [mockAdd({ type: 'release' })],
removed: [],
},
{
revisionId: 2,
updated: [mockAdd({ type: 'test' })],
removed: [],
},
];

const revisions = calculateRequiredClientRevision(revisionList, 0, [
'default',
]);

expect(revisions).toEqual({
revisionId: 2,
updated: [mockAdd({ type: 'test' })],
removed: [],
});
});

test('revision that adds, removes then adds again does not end up with the remove', () => {
const revisionList = [
{
revisionId: 1,
updated: [mockAdd({ name: 'some-toggle' })],
removed: [],
},
{
revisionId: 2,
updated: [],
removed: [
{
name: 'some-toggle',
project: 'default',
},
],
},
{
revisionId: 3,
updated: [mockAdd({ name: 'some-toggle' })],
removed: [],
},
];

const revisions = calculateRequiredClientRevision(revisionList, 0, [
'default',
]);

expect(revisions).toEqual({
revisionId: 3,
updated: [mockAdd({ name: 'some-toggle' })],
removed: [],
});
});

test('revision that removes, adds then removes again does not end up with the remove', () => {
const revisionList = [
{
revisionId: 1,
updated: [],
removed: [
{
name: 'some-toggle',
project: 'default',
},
],
},
{
revisionId: 2,
updated: [mockAdd({ name: 'some-toggle' })],
removed: [],
},
{
revisionId: 3,
updated: [],
removed: [
{
name: 'some-toggle',
project: 'default',
},
],
},
];

const revisions = calculateRequiredClientRevision(revisionList, 0, [
'default',
]);

expect(revisions).toEqual({
revisionId: 3,
updated: [],
removed: [
{
name: 'some-toggle',
project: 'default',
},
],
});
});

test('revision equal to the base case returns only later revisions ', () => {
const revisionList = [
{
revisionId: 1,
updated: [
mockAdd({ name: 'feature1' }),
mockAdd({ name: 'feature2' }),
mockAdd({ name: 'feature3' }),
],
removed: [],
},
{
revisionId: 2,
updated: [mockAdd({ name: 'feature4' })],
removed: [],
},
{
revisionId: 3,
updated: [mockAdd({ name: 'feature5' })],
removed: [],
},
];

const revisions = calculateRequiredClientRevision(revisionList, 1, [
'default',
]);

expect(revisions).toEqual({
revisionId: 3,
updated: [mockAdd({ name: 'feature4' }), mockAdd({ name: 'feature5' })],
removed: [],
});
});

test('project filter removes features not in project', () => {
const revisionList = [
{
revisionId: 1,
updated: [mockAdd({ name: 'feature1', project: 'project1' })],
removed: [],
},
{
revisionId: 2,
updated: [mockAdd({ name: 'feature2', project: 'project2' })],
removed: [],
},
];

const revisions = calculateRequiredClientRevision(revisionList, 0, [
'project1',
]);

expect(revisions).toEqual({
revisionId: 2,
updated: [mockAdd({ name: 'feature1', project: 'project1' })],
removed: [],
});
});
Loading
Loading