From d88aad0cb3e12a9c553afd0b565fc4317b38c480 Mon Sep 17 00:00:00 2001 From: BernardOnuh Date: Wed, 1 Jul 2026 06:27:27 +0100 Subject: [PATCH] fix(backend): stabilize getStreamEvents cursor pagination for tied timestamps Add id as a unique tiebreaker to orderBy so cursor pagination no longer skips or duplicates events that share a timestamp. Fixes #803 --- backend/src/controllers/stream.controller.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/src/controllers/stream.controller.ts b/backend/src/controllers/stream.controller.ts index 5476fb6e..b7670e84 100644 --- a/backend/src/controllers/stream.controller.ts +++ b/backend/src/controllers/stream.controller.ts @@ -316,7 +316,11 @@ export const getStreamEvents = async (req: Request, res: Response) => { const [events, total] = await Promise.all([ prisma.streamEvent.findMany({ where: whereClause, - orderBy: { timestamp: order }, + // `timestamp` is not unique (events in the same block/ledger can + // share a timestamp), so it can't be the sole sort key for cursor + // pagination. Add `id` as a unique tiebreaker so ordering (and + // therefore cursor pagination) is stable across pages. + orderBy: [{ timestamp: order }, { id: order }], take: limit, ...(cursor ? { cursor: { id: cursor }, skip: 1 } @@ -770,4 +774,4 @@ export const resumeStream = async (req: Request, res: Response) => { logger.error('Error resuming stream:', error); return res.status(500).json({ error: 'Internal server error' }); } -}; +}; \ No newline at end of file