mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
Optimize watch history publishing concurrency
- Use pMap for parallel publishing of history months - Increase concurrency limit to 4 for better throughput - Add benchmark script for measuring publish performance Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
b32c3dc39f
commit
ba47ae6963
2 files changed
+70
-1
No files matched your search
@@ -0,0 +1,69 @@
|
||||
|
||||
import { createWatchHistoryManager } from "../js/nostr/watchHistory.js";
|
||||
|
||||
async function main() {
|
||||
console.log("Starting WatchHistoryManager benchmark...");
|
||||
|
||||
// Mock dependencies
|
||||
const mockSigner = {
|
||||
signEvent: async (event) => {
|
||||
// Simulate signing latency
|
||||
await new Promise(resolve => setTimeout(resolve, 10));
|
||||
return { ...event, sig: "mock-sig" };
|
||||
},
|
||||
nip04Encrypt: async (pubkey, plaintext) => {
|
||||
await new Promise(resolve => setTimeout(resolve, 5));
|
||||
return "mock-ciphertext";
|
||||
}
|
||||
};
|
||||
|
||||
const mockPool = {
|
||||
publish: (relays, event) => {
|
||||
return {
|
||||
on: (status, cb) => {
|
||||
if (status === 'ok') {
|
||||
// Simulate network latency
|
||||
setTimeout(cb, 50);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const deps = {
|
||||
ensureNostrTools: async () => ({
|
||||
nip04: { encrypt: async () => "encrypted" },
|
||||
utils: { hexToBytes: () => new Uint8Array(32) }
|
||||
}),
|
||||
getCachedNostrTools: () => ({
|
||||
nip04: { encrypt: async () => "encrypted" },
|
||||
utils: { hexToBytes: () => new Uint8Array(32) }
|
||||
}),
|
||||
getActivePubkey: () => "00".repeat(32),
|
||||
getSessionActor: () => null,
|
||||
resolveActiveSigner: () => mockSigner,
|
||||
getPool: () => mockPool,
|
||||
signEventWithPrivateKey: async () => {
|
||||
await new Promise(resolve => setTimeout(resolve, 10));
|
||||
return { sig: "mock-sig" };
|
||||
},
|
||||
shouldRequestExtensionPermissions: () => false,
|
||||
};
|
||||
|
||||
const manager = createWatchHistoryManager(deps);
|
||||
|
||||
// Create records for 12 months
|
||||
const records = {};
|
||||
for (let i = 1; i <= 12; i++) {
|
||||
const month = `2023-${String(i).padStart(2, '0')}`;
|
||||
records[month] = [{ type: 'e', value: `item-${i}`, watchedAt: 1672531200 + i * 100 }];
|
||||
}
|
||||
|
||||
const start = Date.now();
|
||||
await manager.publishRecords(records, { actorPubkey: "00".repeat(32) });
|
||||
const duration = Date.now() - start;
|
||||
|
||||
console.log(`Published 12 months in ${duration}ms`);
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -1148,7 +1148,7 @@ class WatchHistoryManager {
|
||||
|
||||
return this.publishMonthRecord(month, items, options);
|
||||
},
|
||||
{ concurrency: 3 },
|
||||
{ concurrency: 4 },
|
||||
);
|
||||
|
||||
for (const res of results) {
|
||||
|
||||
Reference in new issue
Block a user