Skip to content

Commit

Permalink
refactor(messages-saga): increase batch interval when receiving new m…
Browse files Browse the repository at this point in the history
…essages (#2077)
  • Loading branch information
domw30 authored Jul 6, 2024
1 parent 8704d1b commit 9d61588
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/store/messages/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,14 @@ export function* receiveDelete(action) {

let savedMessages = [];
export function* receiveNewMessage(action) {
const BATCH_INTERVAL = 2000;

savedMessages.push(action.payload);
if (savedMessages.length > 1) {
// we already have a leading event that's awaiting the debounce delay
return;
}
yield delay(500);
yield delay(BATCH_INTERVAL);
// Clone and empty so follow up events can debounce again
const batchedPayloads = [...savedMessages];
savedMessages = [];
Expand Down

0 comments on commit 9d61588

Please sign in to comment.