Skip to content

Commit e44acf8

Browse files
authored
Merge pull request #977 from BernardOnuh/fix/803-stream-events-cursor-pagination
fix(backend): stabilize getStreamEvents cursor pagination for tied timestamps
2 parents 150f9eb + d88aad0 commit e44acf8

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

backend/src/controllers/stream.controller.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,11 @@ export const getStreamEvents = async (req: Request, res: Response) => {
316316
const [events, total] = await Promise.all([
317317
prisma.streamEvent.findMany({
318318
where: whereClause,
319-
orderBy: { timestamp: order },
319+
// `timestamp` is not unique (events in the same block/ledger can
320+
// share a timestamp), so it can't be the sole sort key for cursor
321+
// pagination. Add `id` as a unique tiebreaker so ordering (and
322+
// therefore cursor pagination) is stable across pages.
323+
orderBy: [{ timestamp: order }, { id: order }],
320324
take: limit,
321325
...(cursor
322326
? { cursor: { id: cursor }, skip: 1 }
@@ -770,4 +774,4 @@ export const resumeStream = async (req: Request, res: Response) => {
770774
logger.error('Error resuming stream:', error);
771775
return res.status(500).json({ error: 'Internal server error' });
772776
}
773-
};
777+
};

0 commit comments

Comments
 (0)