Skip to content

Commit 9b47033

Browse files
authored
Signals: fix max buffer size default (#1233)
1 parent 82bc27b commit 9b47033

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

.changeset/loud-pears-learn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@segment/analytics-signals': patch
3+
---
4+
5+
Fix max buffer size

packages/signals/signals/src/core/buffer/index.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ interface IDBPObjectStoreSignals
2525
'readonly' | 'readwrite' | 'versionchange'
2626
> {}
2727

28+
const MAX_BUFFER_SIZE_DEFAULT = 50
29+
2830
interface StoreSettings {
29-
maxBufferSize: number
31+
maxBufferSize?: number
3032
}
3133
export class SignalStoreIndexDB implements SignalPersistentStorage {
3234
static readonly DB_NAME = 'Segment Signals Buffer'
@@ -50,7 +52,7 @@ export class SignalStoreIndexDB implements SignalPersistentStorage {
5052
}
5153

5254
constructor(settings: StoreSettings) {
53-
this.maxBufferSize = settings.maxBufferSize
55+
this.maxBufferSize = settings.maxBufferSize ?? MAX_BUFFER_SIZE_DEFAULT
5456
this.db = this.initSignalDB()
5557
}
5658

@@ -137,7 +139,7 @@ export class SignalStoreSessionStorage implements SignalPersistentStorage {
137139
private maxBufferSize: number
138140

139141
constructor(settings: StoreSettings) {
140-
this.maxBufferSize = settings.maxBufferSize
142+
this.maxBufferSize = settings.maxBufferSize ?? MAX_BUFFER_SIZE_DEFAULT
141143
}
142144

143145
add(signal: Signal): void {
@@ -216,13 +218,9 @@ export const getSignalBuffer = <
216218
>(
217219
settings: SignalBufferSettingsConfig<T>
218220
) => {
219-
const settingsWithDefaults: StoreSettings = {
220-
maxBufferSize: 50,
221-
...settings,
222-
}
223221
const store =
224222
settings.signalStorage ?? settings.storageType === 'session'
225-
? new SignalStoreSessionStorage(settingsWithDefaults)
226-
: new SignalStoreIndexDB(settingsWithDefaults)
223+
? new SignalStoreSessionStorage(settings)
224+
: new SignalStoreIndexDB(settings)
227225
return new SignalBuffer(store)
228226
}

0 commit comments

Comments
 (0)