From be20aba18961c3700161828203fcc946264dd7ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Dub=C3=A9?= Date: Wed, 30 Oct 2024 03:22:51 +0000 Subject: [PATCH] backwards compatibility --- flow/cmd/mirror_status.go | 31 ++++++++++++++++++++++--------- protos/route.proto | 7 ++++--- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/flow/cmd/mirror_status.go b/flow/cmd/mirror_status.go index ee95aa9c12..c75fc0c7be 100644 --- a/flow/cmd/mirror_status.go +++ b/flow/cmd/mirror_status.go @@ -602,13 +602,15 @@ func (h *FlowRequestHandler) ListMirrorLogs( } sortOrderBy := "desc" - if req.BeforeId != -1 { - whereArgs = append(whereArgs, req.BeforeId) - whereExprs = append(whereExprs, fmt.Sprintf("id < $%d", len(whereArgs))) - } else if req.AfterId != -1 { - whereArgs = append(whereArgs, req.AfterId) - whereExprs = append(whereExprs, fmt.Sprintf("id > $%d", len(whereArgs))) - sortOrderBy = "" + if req.BeforeId != 0 && req.AfterId != 0 { + if req.BeforeId != -1 { + whereArgs = append(whereArgs, req.BeforeId) + whereExprs = append(whereExprs, fmt.Sprintf("id < $%d", len(whereArgs))) + } else if req.AfterId != -1 { + whereArgs = append(whereArgs, req.AfterId) + whereExprs = append(whereExprs, fmt.Sprintf("id > $%d", len(whereArgs))) + sortOrderBy = "" + } } var whereClause string @@ -616,10 +618,16 @@ func (h *FlowRequestHandler) ListMirrorLogs( whereClause = " WHERE " + strings.Join(whereExprs, " AND ") } + // page is deprecated + var offsetClause string + if req.Page != 0 { + offsetClause = fmt.Sprintf(" offset %d", req.Page*req.NumPerPage) + } + rows, err := h.pool.Query(ctx, fmt.Sprintf(`select id, flow_name, error_message, error_type, error_timestamp from peerdb_stats.flow_errors%s order by id %s - limit %d`, whereClause, sortOrderBy, req.NumPerPage), whereArgs...) + limit %d%s`, whereClause, sortOrderBy, req.NumPerPage, offsetClause), whereArgs...) if err != nil { return nil, err } @@ -658,9 +666,14 @@ func (h *FlowRequestHandler) ListMirrorLogs( return nil, err } + page := req.Page + if page == 0 { + page = rowsBehind/req.NumPerPage + 1 + } + return &protos.ListMirrorLogsResponse{ Errors: mirrorErrors, Total: total, - Page: rowsBehind/req.NumPerPage + 1, + Page: page, }, nil } diff --git a/protos/route.proto b/protos/route.proto index 89887141bd..a729f88ac4 100644 --- a/protos/route.proto +++ b/protos/route.proto @@ -359,9 +359,10 @@ message MirrorLog { message ListMirrorLogsRequest { string flow_job_name = 1; string level = 2; - int32 num_per_page = 3; - int32 before_id = 4; - int32 after_id = 5; + int32 page = 3; + int32 num_per_page = 4; + int32 before_id = 5; + int32 after_id = 6; } message ListMirrorLogsResponse { repeated MirrorLog errors = 1;