diff --git a/src/client.ts b/src/client.ts index 374612fc..9d1bc69f 100644 --- a/src/client.ts +++ b/src/client.ts @@ -116,7 +116,7 @@ async function getAncestors(event: Event<1>, result = [] as Event<1>[]): Promise } function getDescendants(eventId: string): Promise[]> { - return getFilter({ kinds: [1], '#e': [eventId] }) as Promise[]>; + return getFilter({ kinds: [1], '#e': [eventId], limit: 200 }) as Promise[]>; } export { getAncestors, getAuthor, getDescendants, getEvent, getFeed, getFollows, pool }; diff --git a/src/controllers/api/statuses.ts b/src/controllers/api/statuses.ts index eda82342..88a4c7d5 100644 --- a/src/controllers/api/statuses.ts +++ b/src/controllers/api/statuses.ts @@ -42,14 +42,21 @@ const createStatusController = validator('json', async (value, c: AppContext) => } }); +// https://stackoverflow.com/a/64820881/8811886 +function wait(ms: number) { + return new Promise((_, reject) => { + setTimeout(() => reject(new Error('timeout succeeded')), ms); + }); +} + const contextController: AppController = async (c) => { const id = c.req.param('id'); const event = await getEvent(id, 1); if (event) { - const ancestorEvents = await getAncestors(event); - const descendantEvents = await getDescendants(event.id); + const ancestorEvents = await Promise.race([wait(1000), getAncestors(event)]) as Event<1>[]; + const descendantEvents = await Promise.race([wait(1000), getDescendants(event.id)]) as Event<1>[]; return c.json({ ancestors: (await Promise.all((ancestorEvents).map(toStatus))).filter(Boolean),