Skip to content

Commit 34cecb8

Browse files
committed
fix(config): fix crashing the entire application when the user does not create a collection
1 parent 83bd150 commit 34cecb8

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/core/buffer/bufferManager.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,32 @@ export const bufferManager = (payload: Payload, pluginOptions: PluginOptions) =>
2323

2424
if (flushStrategy === 'size') {
2525
if (BUFFER.length >= BATCH_SIZE) {
26-
await flushBuffer()
26+
await flushBuffer(pluginOptions)
2727
}
2828
} else if (flushStrategy === 'realtime') {
29-
await flushBuffer()
29+
await flushBuffer(pluginOptions)
3030
}
3131
})
3232

3333
if (flushStrategy === 'time') {
3434
// Every few seconds, empty the buffer (even if it's not full)
3535
setInterval(async () => {
3636
if (BUFFER.length > 0) {
37-
await flushBuffer()
37+
await flushBuffer(pluginOptions)
3838
}
3939
}, FLUSH_INTERVAL)
4040
}
4141
}
4242

43-
const flushBuffer = async () => {
43+
const flushBuffer = async (pluginOptions: PluginOptions) => {
4444
const logsToInsert = [...BUFFER]
4545
BUFFER.length = 0
4646
await Promise.all(
4747
logsToInsert.map((log) =>
4848
payloadInstance.create({
49-
collection: defaultCollectionValues.slug,
49+
collection: pluginOptions.collection?.slug
50+
? pluginOptions.collection?.slug
51+
: defaultCollectionValues.slug,
5052
data: log,
5153
}),
5254
),

0 commit comments

Comments
 (0)