gun
gun copied to clipboard
load() issue
@amark When I used .load(), didn't get all the data one time. Sometimes it skipped some data or return {}. I tried it with 17,000 random messages. I have no issue with on() or open(), once() and load() didn't return all keys that I expected. I have my own relay peer with AWS config in Heroku as well.
import Gun from 'gun/gun';
import 'gun/sea';
import 'gun/lib/radix';
import 'gun/lib/radisk';
import 'gun/lib/store';
import 'gun/lib/rindexed';
import 'gun/lib/open';
import 'gun/lib/load';
import 'gun/lib/then';
const opt = {
peers: ["http://localhost:8765/gun"],
localStorage: false
};
const gun = Gun(opt);
gun.user().auth(userKeyPair, (ack) => {
if (ack.err) {
console.log("Doesn't exist");
} else {
const date = new Date().toISOString();
const payload = {
sender: {
id: "346463",
name: "John Doe"
},
createdAt: "2023-10-26T20:17:53.583Z",
text: "Hello world"
};
const messageRef = gun.user().get("messages").get(date).put(payload);
gun.user([chatroom pub key here]).get("messages").get(date).put(messageRef, null, {opt: {cert: "..."}});
setTimeout(() => {
// For the first time app loads only like restoring data
gun.user().get("messages").load(messages => console.log(messages));
}, 1000);
}
});
@fitouch You can try adding a wait option as the second parameter of load like this:
- gun.user().get("messages").load(messages => console.log(messages));
+ gun.user().get("messages").load(messages => console.log(messages), {wait: timeInMilliseconds});
Try to figure out a minimum timeInMilliseconds that ensures all the data is loaded while ensuring a satisfactory response time.
@trPrince That's what I did. Its not always guaranteed to get all of the data at once.