Skip to content

Commit 4a1dfb2

Browse files
danielskovliclaude
andcommitted
refactor(workflow-engine): simplify paginated query with early-return on empty count
EF Core strips Include() for aggregate queries, so the count is already lightweight. Add early return when totalCount is 0 to skip the data query entirely. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 80d33a2 commit 4a1dfb2

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/Runtime/workflow-engine/src/WorkflowEngine.Data/Repository/EngineRepository.Reads.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,15 @@ await ExecuteWithRetry(
555555
labelFilter: labelFilters
556556
);
557557

558+
// EF Core strips Include() for aggregate queries, so this is a lightweight count
558559
var totalCount = await baseQuery.CountAsync(cancellationToken);
559560

561+
if (totalCount == 0)
562+
{
563+
logger.SuccessfullyFetchedWorkflows(0);
564+
return ([], 0);
565+
}
566+
560567
var workflows = await baseQuery
561568
.OrderBy(wf => wf.CreatedAt)
562569
.Skip((page - 1) * pageSize)

0 commit comments

Comments
 (0)