mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-06 12:52:26 +00:00
Merge pull request #2713 from PR0M3TH3AN/parallel-watch-history-decryption-optimization-3846734436759579183
⚡ Parallelize Watch History Chunk Decryption
This commit is contained in:
1 file changed
+20
-8
@@ -2052,24 +2052,36 @@ class WatchHistoryManager {
|
||||
const chunkEvents = Array.isArray(results)
|
||||
? results.flat().filter((event) => event && typeof event === "object")
|
||||
: [];
|
||||
for (const event of chunkEvents) {
|
||||
const ciphertext = typeof event.content === "string" ? event.content : "";
|
||||
|
||||
const decryptionPromises = chunkEvents.map(async (event) => {
|
||||
const ciphertext =
|
||||
typeof event.content === "string" ? event.content : "";
|
||||
if (!ciphertext) {
|
||||
continue;
|
||||
return null;
|
||||
}
|
||||
let plaintext = "";
|
||||
if (typeof decryptSigner.nip04Decrypt === "function") {
|
||||
try {
|
||||
plaintext = await decryptSigner.nip04Decrypt(actorKey, ciphertext);
|
||||
plaintext = await decryptSigner.nip04Decrypt(
|
||||
actorKey,
|
||||
ciphertext,
|
||||
);
|
||||
} catch (error) {
|
||||
devLogger.warn("[nostr] Failed to decrypt watch history chunk:", error);
|
||||
devLogger.warn(
|
||||
"[nostr] Failed to decrypt watch history chunk:",
|
||||
error,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!plaintext) {
|
||||
continue;
|
||||
return null;
|
||||
}
|
||||
const parsed = parseWatchHistoryPayload(plaintext);
|
||||
if (Array.isArray(parsed.items) && parsed.items.length) {
|
||||
return parseWatchHistoryPayload(plaintext);
|
||||
});
|
||||
|
||||
const decryptedPayloads = await Promise.all(decryptionPromises);
|
||||
for (const parsed of decryptedPayloads) {
|
||||
if (parsed && Array.isArray(parsed.items) && parsed.items.length) {
|
||||
decryptedItems.push(...parsed.items);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user