Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
bouncer: fix duplicates being forwarded to client.
Browse files Browse the repository at this point in the history
Signed-off-by: Yonle <[email protected]>
  • Loading branch information
Yonle committed May 11, 2024
1 parent 1e235a9 commit 7e54d9a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions config.js.example
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ module.exports = {
// Maximum Known Events
// Used for knowing what events has been forwarded to client in order to prevent duplicates to be forwarded.
//
// Setting as 0 will store known events to memory without limits.
max_known_events: 1000,
// Setting as 0 will store known events to memory without limit until the subscription is closed.
// Reduce this value if memory usage is high. But don't go too low as duplicates will be forwarded to client.
max_known_events: 0,

// Wait for every connected relays send EOSE.
// Could improve accuracy on received events.
Expand Down
4 changes: 2 additions & 2 deletions worker_bouncer.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ function newConn(addr, id, reconn_t = 0) {
if (!client.subalias.hasOwnProperty(data[1])) return;
data[1] = client.subalias[data[1]];

if (client.events[data[1]].hasOwnProperty(data[2]?.id)) return; // No need to transmit once it has been transmitted before.
if (client.events[data[1]].has(data[2]?.id)) return; // No need to transmit once it has been transmitted before.
if (!relay.isCache) bc(["EVENT", data[2]], id, true); // store to cache relay
const filter = client.mergedFilters[data[1]];
if (client.pause_subs.has(data[1]) && (filter.since > data[2].created_at) && !relay.isCache) return;
Expand All @@ -334,7 +334,7 @@ function newConn(addr, id, reconn_t = 0) {
if (!relay.isLoadBalancer) client.events[data[1]].add(data[2]?.id);
parentPort.postMessage({ type: "upstream_msg", id, data: JSON.stringify(data) });

if (max_known_events && client.events[data[1]].size > max_known_events)
if (max_known_events && client.events[data[1]].size >= max_known_events)
client.events[data[1]].delete(client.events[data[1]].values().next().value);

stats._global.rx++;
Expand Down

0 comments on commit 7e54d9a

Please sign in to comment.