Skip to content

Commit b74143b

Browse files
committed
fix: consider live workflows when checking HasMoreWorkflows
Fix pagination logic to properly check for more workflows when there are many live workflows in the cluster. Previously, HasMoreWorkflows only checked the archive, ignoring live workflows. - Check if current offset+limit is still within live workflows range - If within live range, there are definitely more items - If beyond live range, check archive with adjusted offset - Fixes incorrect pagination when live workflows exceed offset+limit Signed-off-by: shuangkun <[email protected]>
1 parent 1d00f49 commit b74143b

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

server/workflow/workflow_server.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,33 @@ func (s *workflowServer) ListWorkflows(ctx context.Context, req *workflowpkg.Wor
255255
} else {
256256
// For pagination without remaining count, use the efficient HasMoreWorkflows method
257257
// This avoids expensive COUNT queries
258-
hasMore, err := s.wfArchive.HasMoreWorkflows(ctx, options)
259-
if err != nil {
260-
return nil, sutils.ToStatusError(err, codes.Internal)
258+
// Need to check both live workflows and archived workflows
259+
hasMoreLive := false
260+
if options.Limit > 0 {
261+
// Check if there are more live workflows beyond the current offset+limit
262+
hasMoreLive = int64(options.Offset+options.Limit) < liveWfCount
263+
} else {
264+
// If limit is 0, we're requesting all items, so no pagination needed
265+
hasMoreLive = false
261266
}
262-
if hasMore {
267+
268+
hasMoreArchived := false
269+
if !hasMoreLive {
270+
// Only check archived workflows if we've exhausted live workflows
271+
// Adjust offset to account for live workflows when checking archive
272+
archivedOffset := options.Offset - int(liveWfCount)
273+
if archivedOffset < 0 {
274+
archivedOffset = 0
275+
}
276+
archivedOptions := options.WithOffset(archivedOffset)
277+
hasMore, err := s.wfArchive.HasMoreWorkflows(ctx, archivedOptions)
278+
if err != nil {
279+
return nil, sutils.ToStatusError(err, codes.Internal)
280+
}
281+
hasMoreArchived = hasMore
282+
}
283+
284+
if hasMoreLive || hasMoreArchived {
263285
remainCount = 1 // There are more items
264286
} else {
265287
remainCount = 0 // No more items

0 commit comments

Comments
 (0)