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

fix: concurrent event triggering unnecessary flush call #113

Merged
merged 3 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "@rudderstack/rudder-sdk-node",
"version": "2.0.3",
"description": "Rudder Node SDK",
"main": "./cjs/index.js",
"module": "./esm/index.js",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
MoumitaM marked this conversation as resolved.
Show resolved Hide resolved
"types": "./index.d.ts",
"license": "",
"repository": "rudderlabs/rudder-sdk-node",
Expand Down
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,10 @@ class Analytics {
return Promise.resolve();
}

// remove items from the queue before awaiting for the pending flush
// to avoid concurrent events triggering unnecessary flush API calls
const items = this.queue.splice(0, this.flushAt);

saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
try {
if (this.pendingFlush) {
await this.pendingFlush;
Expand All @@ -620,7 +624,6 @@ class Analytics {
throw err;
}

const items = this.queue.splice(0, this.flushAt);
const callbacks = items.map((item) => item.callback);
const messages = items.map((item) => {
// if someone mangles directly with queue
Expand Down
Loading