Fix pagination bug

This commit is contained in:
Jesse Wierzbinski 2024-04-07 16:32:45 -10:00
parent e0335c33a9
commit d3a625e084
No known key found for this signature in database

View file

@ -5,6 +5,8 @@ export async function fetchTimeline<T extends User | Status>(
args: Prisma.StatusFindManyArgs | Prisma.UserFindManyArgs, args: Prisma.StatusFindManyArgs | Prisma.UserFindManyArgs,
req: Request, req: Request,
) { ) {
// BEFORE: Before in a top-to-bottom order, so the most recent posts
// AFTER: After in a top-to-bottom order, so the oldest posts
// @ts-expect-error This is a hack to get around the fact that Prisma doesn't have a common base type for all models // @ts-expect-error This is a hack to get around the fact that Prisma doesn't have a common base type for all models
const objects = (await model.findMany(args)) as T[]; const objects = (await model.findMany(args)) as T[];
@ -49,9 +51,7 @@ export async function fetchTimeline<T extends User | Status>(
const urlWithoutQuery = req.url.split("?")[0]; const urlWithoutQuery = req.url.split("?")[0];
// Add next link // Add next link
linkHeader.push( linkHeader.push(
`<${urlWithoutQuery}?max_id=${ `<${urlWithoutQuery}?max_id=${objectsAfter[0].id}>; rel="next"`,
objects.at(-1)?.id
}>; rel="next"`,
); );
} }
} }