mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Try setting a timeout for context endpoint
This commit is contained in:
parent
7bb8821b1b
commit
3da9ffab9e
2 changed files with 10 additions and 3 deletions
|
|
@ -116,7 +116,7 @@ async function getAncestors(event: Event<1>, result = [] as Event<1>[]): Promise
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDescendants(eventId: string): Promise<SignedEvent<1>[]> {
|
function getDescendants(eventId: string): Promise<SignedEvent<1>[]> {
|
||||||
return getFilter({ kinds: [1], '#e': [eventId] }) as Promise<SignedEvent<1>[]>;
|
return getFilter({ kinds: [1], '#e': [eventId], limit: 200 }) as Promise<SignedEvent<1>[]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { getAncestors, getAuthor, getDescendants, getEvent, getFeed, getFollows, pool };
|
export { getAncestors, getAuthor, getDescendants, getEvent, getFeed, getFollows, pool };
|
||||||
|
|
|
||||||
|
|
@ -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 contextController: AppController = async (c) => {
|
||||||
const id = c.req.param('id');
|
const id = c.req.param('id');
|
||||||
|
|
||||||
const event = await getEvent(id, 1);
|
const event = await getEvent(id, 1);
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
const ancestorEvents = await getAncestors(event);
|
const ancestorEvents = await Promise.race([wait(1000), getAncestors(event)]) as Event<1>[];
|
||||||
const descendantEvents = await getDescendants(event.id);
|
const descendantEvents = await Promise.race([wait(1000), getDescendants(event.id)]) as Event<1>[];
|
||||||
|
|
||||||
return c.json({
|
return c.json({
|
||||||
ancestors: (await Promise.all((ancestorEvents).map(toStatus))).filter(Boolean),
|
ancestors: (await Promise.all((ancestorEvents).map(toStatus))).filter(Boolean),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue