amark / gun

An open source cybersecurity protocol for syncing decentralized graph data.
https://gun.eco/docs
Other
18.16k stars 1.17k forks source link

Simple example with map() returns lots of results when should return one #524

Open natew opened 6 years ago

natew commented 6 years ago

Running the following on node 9:

image

Logs a ton of stuff:

image

Stefdv commented 6 years ago

This has to do with the 'streaming' nature of Gun. You could filter out redundant messages in your callback or use a module like 'open()' https://gun.eco/docs/API#-a-name-open-a-gun-open-callback- or synclist() https://www.npmjs.com/package/gun-synclist

amark commented 6 years ago

@Stefdv thanks for those mentions, although I think the 1st link got messed up, here it is: https://gun.eco/docs/API#open

@natew yeah, another easy fix is to do .map().once(cb) which will only grab each item once.

Ideally, I want to get the duplicate events fixed, but because .on(cb) subscribes, and the same data may come from multiple adapters (memory, disk, S3, IPFS, etc.) and from other peers. (And even if you don't have any other adapters/peers, on is sometimes "chatty") this technically isn't wrong behavior, but yes it should be improved at some point in the future.