mirror of
https://github.com/aljazceru/ditto.git
synced 2025-12-18 22:14:23 +01:00
Add query timeouts
This commit is contained in:
@@ -73,11 +73,15 @@ function connectStream(socket: WebSocket) {
|
||||
const pubsub = await Storages.pubsub();
|
||||
|
||||
try {
|
||||
for (const event of await store.query(filters, { limit: FILTER_LIMIT })) {
|
||||
for (const event of await store.query(filters, { limit: FILTER_LIMIT, timeout: 500 })) {
|
||||
send(['EVENT', subId, event]);
|
||||
}
|
||||
} catch (e) {
|
||||
send(['CLOSED', subId, e.message]);
|
||||
if (e instanceof RelayError) {
|
||||
send(['CLOSED', subId, e.message]);
|
||||
} else {
|
||||
send(['CLOSED', subId, 'error: something went wrong']);
|
||||
}
|
||||
controllers.delete(subId);
|
||||
return;
|
||||
}
|
||||
@@ -124,7 +128,7 @@ function connectStream(socket: WebSocket) {
|
||||
/** Handle COUNT. Return the number of events matching the filters. */
|
||||
async function handleCount([_, subId, ...filters]: NostrClientCOUNT): Promise<void> {
|
||||
const store = await Storages.db();
|
||||
const { count } = await store.count(filters);
|
||||
const { count } = await store.count(filters, { timeout: 500 });
|
||||
send(['COUNT', subId, { count, approximate: false }]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user