Add debug logging: per-relay publish/timeout/reject with elapsed time, batch start/end timing

This commit is contained in:
Laan Tungir
2026-06-30 11:07:27 -04:00
parent 9b746838c3
commit b03b848909
2 changed files with 15 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
{
"VERSION": "v0.7.81",
"VERSION_NUMBER": "0.7.81",
"BUILD_DATE": "2026-06-30T14:55:04.841Z"
"VERSION": "v0.7.82",
"VERSION_NUMBER": "0.7.82",
"BUILD_DATE": "2026-06-30T15:07:27.716Z"
}

View File

@@ -6233,11 +6233,16 @@ async function handlePublish(requestId, event, port) {
latestRelay: null,
});
// Debug: track publish start time for timing analysis
const publishStartTime = Date.now();
ndkEvent.on('relay:published', (relay) => {
const url = relay?.url || String(relay || '');
if (!url) return;
const elapsed = ((Date.now() - publishStartTime) / 1000).toFixed(1);
publishedSoFar.add(url);
trackRelayWrite(url);
console.log(`[Worker][broadcast] ✅ ${url} published (${elapsed}s) — batch ${currentBatch}/${totalBatches}, ${publishedSoFar.size}/${totalTarget} total`);
broadcast({
type: 'broadcastProgress',
sessionId: publishSessionId,
@@ -6255,11 +6260,14 @@ async function handlePublish(requestId, event, port) {
const url = relay?.url || String(relay || '');
if (!url) return;
const errMsg = err?.message || String(err) || '';
const elapsed = ((Date.now() - publishStartTime) / 1000).toFixed(1);
const isTimeout = /timeout/i.test(errMsg);
if (isTimeout) {
timedOutSoFar.add(url);
console.log(`[Worker][broadcast] ⏱️ ${url} TIMEOUT (${elapsed}s) — batch ${currentBatch}/${totalBatches}`);
} else {
failedSoFar.add(url);
console.log(`[Worker][broadcast] ❌ ${url} REJECTED (${elapsed}s): ${errMsg} — batch ${currentBatch}/${totalBatches}`);
}
broadcast({
type: 'broadcastProgress',
@@ -6348,6 +6356,8 @@ async function handlePublish(requestId, event, port) {
for (let bi = 0; bi < batches.length; bi++) {
currentBatch = bi + 1; // update before publish so per-relay events include it
const batch = batches[bi];
const batchStartTime = Date.now();
console.log(`[Worker][broadcast] Batch ${bi + 1}/${totalBatches} starting — ${batch.length} relays: ${batch.slice(0, 5).join(', ')}${batch.length > 5 ? '...' : ''}`);
const batchSet = NDKRelaySet.fromRelayUrls(batch, ndk);
if (batchSet?.relays) {
for (const relay of batchSet.relays) {
@@ -6375,7 +6385,8 @@ async function handlePublish(requestId, event, port) {
batchCurrent: bi + 1,
batchTotal: totalBatches,
});
console.log(`[Worker] Batch ${bi + 1}/${totalBatches} complete — ` +
const batchElapsed = ((Date.now() - batchStartTime) / 1000).toFixed(1);
console.log(`[Worker] Batch ${bi + 1}/${totalBatches} complete (${batchElapsed}s) — ` +
`${publishedSoFar.size}/${totalTarget} total succeeded, ` +
`${failedSoFar.size + timedOutSoFar.size} failed/timeout so far`);
}