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

Performance issues #422

Open
jimtracy1007 opened this issue Jul 29, 2024 · 5 comments
Open

Performance issues #422

jimtracy1007 opened this issue Jul 29, 2024 · 5 comments

Comments

@jimtracy1007
Copy link

I use version v2.0+for message sending and receiving, which is very slow, and the filtering conditions for receiving messages do not take effect in the new version.
`
async function execSendMessageAndReturn({ message, from, to, sk, kind = 4 }) {

const tags = to ? [
    ["p", to],
    ["r", "json"]
] : []
const event = await buildEvent({
    message: message,
    kind: kind,
    targetPubkey: to,
    privateKey: sk,
    tags: tags,
});


await Promise.any(pool.publish(relays, event))

const p = getPublicKey(sk);

const filter = {
    since: event.created_at - 50,
    kinds: [4],
    '#e': [event.id],
    '#p': [p]
};

const retEvent = await pool.get(relays, filter, { maxWait: 5000 }).catch((e) => {
    console.log('e.message---->', e.message)
    return null;
});

if (!retEvent) {
    return null;
}
const content = retEvent.content;

const decryptContent = await nip04.decrypt(sk, to, content).catch(e => {
    console.error('decryptContent error', e.message)
});

if (decryptContent) {
    try {
        result = JSON.parse(decryptContent);
    } catch (error) {
        console.log("🚀 ~ execSendMessageAndReturn ~ error:", error)
        return null
    }
    return result;
}

}
`
const filter = {
since: event.created_at - 50,
kinds: [4],
'#e': [event.id],
'#p': [p]
}; This code does not take effect in the new version.

@jimtracy1007
Copy link
Author

If I only use the filter like
const filter = {'#e':[event.id]},The response will be very slow. But version 1.17.0 is very fast.

@fiatjaf
Copy link
Collaborator

fiatjaf commented Jul 29, 2024

I think on v2 we switched to pure JavaScript decryption, while before we were using the browser native libraries.

@jimtracy1007
Copy link
Author

I think on v2 we switched to pure JavaScript decryption, while before we were using the browser native libraries.

However, how to deal with the problem of slow reception

@fiatjaf
Copy link
Collaborator

fiatjaf commented Jul 30, 2024

You can rewrite the logic using browser libraries (or copy the old code from v1) in your app.

I think you should be using NIP-17 for DMs though, it is much better and hopefully everybody will be moving to it soon.

@jimwjl666
Copy link

您可以在应用程序中使用浏览器库重写逻辑(或从 v1 复制旧代码)。

我认为您应该对 DM 使用 NIP-17,它要好得多,希望每个人都能尽快转向它。

nip-44?

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

3 participants