From c271506af96c7831e7701970498d0607595a0509 Mon Sep 17 00:00:00 2001 From: Wes Date: Thu, 2 Nov 2023 09:32:38 -0700 Subject: [PATCH] fix: event ordering when more than 1000 events logged (#538) Fixes #490 --- backend/controller/internal/dal/events.go | 8 ++++---- frontend/src/services/console.service.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/controller/internal/dal/events.go b/backend/controller/internal/dal/events.go index cd7a346fcd..d81419307a 100644 --- a/backend/controller/internal/dal/events.go +++ b/backend/controller/internal/dal/events.go @@ -236,10 +236,10 @@ func (d *DAL) QueryEvents(ctx context.Context, limit int, filters ...EventFilter return index - 1 } if !filter.olderThan.IsZero() { - q += fmt.Sprintf(" AND time_stamp <= $%d::TIMESTAMPTZ", param(filter.olderThan)) + q += fmt.Sprintf(" AND e.time_stamp <= $%d::TIMESTAMPTZ", param(filter.olderThan)) } if !filter.newerThan.IsZero() { - q += fmt.Sprintf(" AND time_stamp >= $%d::TIMESTAMPTZ", param(filter.newerThan)) + q += fmt.Sprintf(" AND e.time_stamp >= $%d::TIMESTAMPTZ", param(filter.newerThan)) } if filter.idHigherThan != 0 { q += fmt.Sprintf(" AND e.id >= $%d::BIGINT", param(filter.idHigherThan)) @@ -279,9 +279,9 @@ func (d *DAL) QueryEvents(ctx context.Context, limit int, filters ...EventFilter } if filter.descending { - q += " ORDER BY time_stamp DESC" + q += " ORDER BY e.time_stamp DESC, e.id DESC" } else { - q += " ORDER BY time_stamp ASC" + q += " ORDER BY e.time_stamp ASC, e.id ASC" } q += fmt.Sprintf(" LIMIT %d", limit) diff --git a/frontend/src/services/console.service.ts b/frontend/src/services/console.service.ts index 60aa77b9ba..eb05b27bdd 100644 --- a/frontend/src/services/console.service.ts +++ b/frontend/src/services/console.service.ts @@ -170,14 +170,14 @@ export const streamEvents = async ({ try { let events: Event[] = [] for await (const response of client.streamEvents( - { updateInterval: { seconds: BigInt(1) }, query: { limit: 1000, filters } }, + { updateInterval: { seconds: BigInt(1) }, query: { limit: 1000, filters, order: EventsQuery_Order.DESC } }, { signal: abortControllerSignal }, )) { if (response.event != null) { events.push(response.event) } if (!response.more) { - onEventsReceived(events.reverse()) + onEventsReceived(events) events = [] } }