From 092a20088a5ae82a89ce71b034b0b24e61b4b480 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 1 Jul 2024 09:18:42 +0100 Subject: [PATCH] Reduce timeouts --- src/controllers/nostr/relay.ts | 4 ++-- src/storages/EventsDB.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/controllers/nostr/relay.ts b/src/controllers/nostr/relay.ts index e86f1991..6d79b031 100644 --- a/src/controllers/nostr/relay.ts +++ b/src/controllers/nostr/relay.ts @@ -73,7 +73,7 @@ function connectStream(socket: WebSocket) { const pubsub = await Storages.pubsub(); try { - for (const event of await store.query(filters, { limit: FILTER_LIMIT, timeout: 500 })) { + for (const event of await store.query(filters, { limit: FILTER_LIMIT, timeout: 300 })) { send(['EVENT', subId, event]); } } catch (e) { @@ -128,7 +128,7 @@ function connectStream(socket: WebSocket) { /** Handle COUNT. Return the number of events matching the filters. */ async function handleCount([_, subId, ...filters]: NostrClientCOUNT): Promise { const store = await Storages.db(); - const { count } = await store.count(filters, { timeout: 500 }); + const { count } = await store.count(filters, { timeout: 100 }); send(['COUNT', subId, { count, approximate: false }]); } diff --git a/src/storages/EventsDB.ts b/src/storages/EventsDB.ts index 664be893..61b87b00 100644 --- a/src/storages/EventsDB.ts +++ b/src/storages/EventsDB.ts @@ -63,7 +63,7 @@ class EventsDB implements NStore { await this.deleteEventsAdmin(event); try { - await this.store.event(event, { ...opts, timeout: opts.timeout ?? 3000 }); + await this.store.event(event, { ...opts, timeout: opts.timeout ?? 1000 }); } catch (e) { if (e.message === 'Cannot add a deleted event') { throw new RelayError('blocked', 'event deleted by user'); @@ -163,7 +163,7 @@ class EventsDB implements NStore { this.console.debug('REQ', JSON.stringify(filters)); - return this.store.query(filters, { ...opts, timeout: opts.timeout ?? 3000 }); + return this.store.query(filters, { ...opts, timeout: opts.timeout ?? 1000 }); } /** Delete events based on filters from the database. */ @@ -171,7 +171,7 @@ class EventsDB implements NStore { if (!filters.length) return Promise.resolve(); this.console.debug('DELETE', JSON.stringify(filters)); - return this.store.remove(filters, { ...opts, timeout: opts.timeout ?? 5000 }); + return this.store.remove(filters, { ...opts, timeout: opts.timeout ?? 3000 }); } /** Get number of events that would be returned by filters. */ @@ -184,7 +184,7 @@ class EventsDB implements NStore { this.console.debug('COUNT', JSON.stringify(filters)); - return this.store.count(filters, { ...opts, timeout: opts.timeout ?? 1000 }); + return this.store.count(filters, { ...opts, timeout: opts.timeout ?? 500 }); } /** Return only the tags that should be indexed. */