Skip to content

Commit db2fa33

Browse files
committed
Remove allowEviction
1 parent bca65dd commit db2fa33

File tree

2 files changed

+7
-29
lines changed

2 files changed

+7
-29
lines changed

packages/core/src/utils/featureFlags.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,12 @@ export function _INTERNAL_insertFlagToScope(
8383
* @param name Name of the feature flag to insert.
8484
* @param value Value of the feature flag.
8585
* @param maxSize Max number of flags the buffer should store. Default value should always be used in production.
86-
* @param allowEviction If true, the oldest flag is evicted when the buffer is full. Otherwise the new flag is dropped.
8786
*/
8887
export function _INTERNAL_insertToFlagBuffer(
8988
flags: FeatureFlag[],
9089
name: string,
9190
value: unknown,
9291
maxSize: number,
93-
allowEviction: boolean = true,
9492
): void {
9593
if (typeof value !== 'boolean') {
9694
return;
@@ -110,12 +108,8 @@ export function _INTERNAL_insertToFlagBuffer(
110108
}
111109

112110
if (flags.length === maxSize) {
113-
if (allowEviction) {
114-
// If at capacity, pop the earliest flag - O(n)
115-
flags.shift();
116-
} else {
117-
return;
118-
}
111+
// If at capacity, pop the earliest flag - O(n)
112+
flags.shift();
119113
}
120114

121115
// Push the flag to the end - O(1)

packages/core/test/lib/utils/featureFlags.test.ts

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { afterEach, describe, expect, it, vi } from 'vitest';
22
import { getCurrentScope } from '../../../src/currentScopes';
3-
import { type FeatureFlag } from '../../../src/featureFlags';
4-
import { _INTERNAL_insertFlagToScope, _INTERNAL_insertToFlagBuffer } from '../../../src/utils/featureFlags';
3+
import {
4+
type FeatureFlag,
5+
_INTERNAL_insertFlagToScope,
6+
_INTERNAL_insertToFlagBuffer,
7+
} from '../../../src/utils/featureFlags';
58
import { logger } from '../../../src/utils-hoist/logger';
69

710
describe('flags', () => {
@@ -60,25 +63,6 @@ describe('flags', () => {
6063
]);
6164
});
6265

63-
it('drops new entries when allowEviction is false and buffer is full', () => {
64-
const buffer: FeatureFlag[] = [];
65-
const maxSize = 0;
66-
_INTERNAL_insertToFlagBuffer(buffer, 'feat1', true, maxSize, false);
67-
_INTERNAL_insertToFlagBuffer(buffer, 'feat2', true, maxSize, false);
68-
_INTERNAL_insertToFlagBuffer(buffer, 'feat3', true, maxSize, false);
69-
70-
expect(buffer).toEqual([]);
71-
});
72-
73-
it('still updates order and values when allowEviction is false and buffer is full', () => {
74-
const buffer: FeatureFlag[] = [];
75-
const maxSize = 1;
76-
_INTERNAL_insertToFlagBuffer(buffer, 'feat1', false, maxSize, false);
77-
_INTERNAL_insertToFlagBuffer(buffer, 'feat1', true, maxSize, false);
78-
79-
expect(buffer).toEqual([{ flag: 'feat1', result: true }]);
80-
});
81-
8266
it('does not allocate unnecessary space', () => {
8367
const buffer: FeatureFlag[] = [];
8468
const maxSize = 1000;

0 commit comments

Comments
 (0)