mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-01 10:22:25 +00:00
Merge pull request #2110 from PR0M3TH3AN/perf-watch-history-parallel-decryption-8829981106399700289
⚡ Parallelize watch history decryption
This commit is contained in:
1 file changed
+9
-5
@@ -1901,10 +1901,10 @@ class WatchHistoryManager {
|
||||
const chunkEvents = Array.isArray(results)
|
||||
? results.flat().filter((event) => event && typeof event === "object")
|
||||
: [];
|
||||
for (const event of chunkEvents) {
|
||||
const decryptionPromises = chunkEvents.map(async (event) => {
|
||||
const ciphertext = typeof event.content === "string" ? event.content : "";
|
||||
if (!ciphertext) {
|
||||
continue;
|
||||
return [];
|
||||
}
|
||||
let plaintext = "";
|
||||
if (typeof decryptSigner.nip04Decrypt === "function") {
|
||||
@@ -1915,13 +1915,17 @@ class WatchHistoryManager {
|
||||
}
|
||||
}
|
||||
if (!plaintext) {
|
||||
continue;
|
||||
return [];
|
||||
}
|
||||
const parsed = parseWatchHistoryPayload(plaintext);
|
||||
if (Array.isArray(parsed.items) && parsed.items.length) {
|
||||
decryptedItems.push(...parsed.items);
|
||||
return parsed.items;
|
||||
}
|
||||
}
|
||||
return [];
|
||||
});
|
||||
|
||||
const chunkResults = await Promise.all(decryptionPromises);
|
||||
decryptedItems.push(...chunkResults.flat());
|
||||
} catch (error) {
|
||||
devLogger.warn("[nostr] Failed to fetch watch history chunks:", error);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user