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

load() issue #1346

Open
fitouch opened this issue Dec 14, 2023 · 2 comments
Open

load() issue #1346

fitouch opened this issue Dec 14, 2023 · 2 comments

Comments

@fitouch
Copy link

fitouch commented Dec 14, 2023

@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);
    }
});
@trPrince
Copy link

trPrince commented Mar 13, 2024

@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.

@fitouch
Copy link
Author

fitouch commented Mar 16, 2024

@trPrince That's what I did. Its not always guaranteed to get all of the data at once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants