|
|
|
|
@@ -1049,9 +1049,8 @@ function pruneSeenEventIds(seenEventIds) {
|
|
|
|
|
function wireSubscriptionHandlers(subId, state, filtersForCache) {
|
|
|
|
|
if (!state?.sub) return;
|
|
|
|
|
|
|
|
|
|
state.sub.on('event', async (event) => {
|
|
|
|
|
state.sub.on('event', (event) => {
|
|
|
|
|
if (state.seenEventIds.has(event.id)) {
|
|
|
|
|
console.log('[Worker] Dedup dropped event for sub:', subId, 'id:', event.id);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1063,14 +1062,7 @@ function wireSubscriptionHandlers(subId, state, filtersForCache) {
|
|
|
|
|
state.lastEventCreatedAt = Math.max(Number(state.lastEventCreatedAt || 0), createdAt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('[Worker] Event received for sub:', subId, 'kind:', event.kind, 'id:', event.id);
|
|
|
|
|
|
|
|
|
|
if (isWorkerEventMuted(event)) {
|
|
|
|
|
console.log('[Worker][mute] Filtered muted event for sub:', subId, {
|
|
|
|
|
id: event?.id || null,
|
|
|
|
|
kind: event?.kind || null,
|
|
|
|
|
pubkey: event?.pubkey || null,
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1079,14 +1071,14 @@ function wireSubscriptionHandlers(subId, state, filtersForCache) {
|
|
|
|
|
trackRelayRead(event.relay.url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Cache the event to IndexedDB
|
|
|
|
|
// Cache the event to IndexedDB — fire-and-forget (NOT awaited).
|
|
|
|
|
// Awaiting serializes all incoming events through IndexedDB I/O,
|
|
|
|
|
// which blocks the worker's event loop and starves port.onmessage
|
|
|
|
|
// handlers (getRelayData, getRelayStats, etc.), causing 15s timeouts
|
|
|
|
|
// and relay indicators disappearing over extended sessions.
|
|
|
|
|
if (ndk.cacheAdapter && typeof ndk.cacheAdapter.setEvent === 'function') {
|
|
|
|
|
try {
|
|
|
|
|
await ndk.cacheAdapter.setEvent(event, filtersForCache, event.relay);
|
|
|
|
|
console.log('[Worker] Cached event:', event.id, 'from relay:', event.relay?.url);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('[Worker] Failed to cache event:', error);
|
|
|
|
|
}
|
|
|
|
|
void ndk.cacheAdapter.setEvent(event, filtersForCache, event.relay)
|
|
|
|
|
.catch(error => console.error('[Worker] Failed to cache event:', error));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
broadcast({
|
|
|
|
|
|