publicController: return early if there are no events

This commit is contained in:
Alex Gleason 2023-07-07 15:15:26 -05:00
parent d4eef9c2af
commit b7ecc609de
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 8 additions and 3 deletions

View File

@ -26,10 +26,15 @@ const homeController: AppController = async (c) => {
const publicController: AppController = async (c) => {
const params = paginationSchema.parse(c.req.query());
const events = await getPublicFeed(params);
const statuses = (await Promise.all(events.map(toStatus))).filter(Boolean);
const link = buildLinkHeader(c.req.url, events);
const events = await getPublicFeed(params);
if (!events.length) {
return c.json([]);
}
const statuses = (await Promise.all(events.map(toStatus))).filter(Boolean);
const link = buildLinkHeader(c.req.url, events);
return c.json(statuses, 200, link ? { link } : undefined);
};