mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-01 02:12:26 +00:00
Merge pull request #2120 from PR0M3TH3AN/perf-watch-history-concurrency-10087713430403090504
⚡ Optimize watch history chunk decryption concurrency
This commit is contained in:
1 file changed
+24
-22
+24
-22
@@ -1908,30 +1908,32 @@ class WatchHistoryManager {
|
||||
const chunkEvents = Array.isArray(results)
|
||||
? results.flat().filter((event) => event && typeof event === "object")
|
||||
: [];
|
||||
const decryptionPromises = chunkEvents.map(async (event) => {
|
||||
const ciphertext = typeof event.content === "string" ? event.content : "";
|
||||
if (!ciphertext) {
|
||||
return [];
|
||||
}
|
||||
let plaintext = "";
|
||||
if (typeof decryptSigner.nip04Decrypt === "function") {
|
||||
try {
|
||||
plaintext = await decryptSigner.nip04Decrypt(actorKey, ciphertext);
|
||||
} catch (error) {
|
||||
devLogger.warn("[nostr] Failed to decrypt watch history chunk:", error);
|
||||
const chunkResults = await pMap(
|
||||
chunkEvents,
|
||||
async (event) => {
|
||||
const ciphertext = typeof event.content === "string" ? event.content : "";
|
||||
if (!ciphertext) {
|
||||
return [];
|
||||
}
|
||||
let plaintext = "";
|
||||
if (typeof decryptSigner.nip04Decrypt === "function") {
|
||||
try {
|
||||
plaintext = await decryptSigner.nip04Decrypt(actorKey, ciphertext);
|
||||
} catch (error) {
|
||||
devLogger.warn("[nostr] Failed to decrypt watch history chunk:", error);
|
||||
}
|
||||
}
|
||||
if (!plaintext) {
|
||||
return [];
|
||||
}
|
||||
const parsed = parseWatchHistoryPayload(plaintext);
|
||||
if (Array.isArray(parsed.items) && parsed.items.length) {
|
||||
return parsed.items;
|
||||
}
|
||||
}
|
||||
if (!plaintext) {
|
||||
return [];
|
||||
}
|
||||
const parsed = parseWatchHistoryPayload(plaintext);
|
||||
if (Array.isArray(parsed.items) && parsed.items.length) {
|
||||
return parsed.items;
|
||||
}
|
||||
return [];
|
||||
});
|
||||
|
||||
const chunkResults = await Promise.all(decryptionPromises);
|
||||
},
|
||||
{ concurrency: 5 },
|
||||
);
|
||||
decryptedItems.push(...chunkResults.flat());
|
||||
} catch (error) {
|
||||
devLogger.warn("[nostr] Failed to fetch watch history chunks:", error);
|
||||
|
||||
Reference in new issue
Block a user