From a51b8d31c476c9072b6cea1d40561cec77e44bc6 Mon Sep 17 00:00:00 2001 From: tutran985 Date: Tue, 3 Feb 2026 13:58:57 +0700 Subject: [PATCH] perf(entgql): avoid COUNT(*) for pageInfo-only connection queries --- entgql/internal/todo/ent/gql_pagination.go | 18 +++++++++--------- entgql/internal/todofed/ent/gql_pagination.go | 4 ++-- .../todoglobalid/ent/gql_pagination.go | 18 +++++++++--------- .../internal/todogotype/ent/gql_pagination.go | 14 +++++++------- .../internal/todopulid/ent/gql_pagination.go | 12 ++++++------ entgql/internal/todouuid/ent/gql_pagination.go | 12 ++++++------ entgql/template/pagination.tmpl | 2 +- 7 files changed, 40 insertions(+), 40 deletions(-) diff --git a/entgql/internal/todo/ent/gql_pagination.go b/entgql/internal/todo/ent/gql_pagination.go index 89d25786a..2195cb069 100644 --- a/entgql/internal/todo/ent/gql_pagination.go +++ b/entgql/internal/todo/ent/gql_pagination.go @@ -292,7 +292,7 @@ func (bp *BillProductQuery) Paginate( } conn := &BillProductConnection{Edges: []*BillProductEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := bp.Clone() @@ -590,7 +590,7 @@ func (c *CategoryQuery) Paginate( } conn := &CategoryConnection{Edges: []*CategoryEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := c.Clone() @@ -981,7 +981,7 @@ func (f *FriendshipQuery) Paginate( } conn := &FriendshipConnection{Edges: []*FriendshipEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := f.Clone() @@ -1266,7 +1266,7 @@ func (gr *GroupQuery) Paginate( } conn := &GroupConnection{Edges: []*GroupEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := gr.Clone() @@ -1515,7 +1515,7 @@ func (otm *OneToManyQuery) Paginate( } conn := &OneToManyConnection{Edges: []*OneToManyEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := otm.Clone() @@ -1811,7 +1811,7 @@ func (pr *ProjectQuery) Paginate( } conn := &ProjectConnection{Edges: []*ProjectEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := pr.Clone() @@ -2109,7 +2109,7 @@ func (t *TodoQuery) Paginate( } conn := &TodoConnection{Edges: []*TodoEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := t.Clone() @@ -2539,7 +2539,7 @@ func (u *UserQuery) Paginate( } conn := &UserConnection{Edges: []*UserEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := u.Clone() @@ -2843,7 +2843,7 @@ func (w *WorkspaceQuery) Paginate( } conn := &OrganizationConnection{Edges: []*OrganizationEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := w.Clone() diff --git a/entgql/internal/todofed/ent/gql_pagination.go b/entgql/internal/todofed/ent/gql_pagination.go index 6db8d185c..ce8f8c874 100644 --- a/entgql/internal/todofed/ent/gql_pagination.go +++ b/entgql/internal/todofed/ent/gql_pagination.go @@ -285,7 +285,7 @@ func (c *CategoryQuery) Paginate( } conn := &CategoryConnection{Edges: []*CategoryEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := c.Clone() @@ -599,7 +599,7 @@ func (t *TodoQuery) Paginate( } conn := &TodoConnection{Edges: []*TodoEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := t.Clone() diff --git a/entgql/internal/todoglobalid/ent/gql_pagination.go b/entgql/internal/todoglobalid/ent/gql_pagination.go index 61e9f7ff3..4117d8bfe 100644 --- a/entgql/internal/todoglobalid/ent/gql_pagination.go +++ b/entgql/internal/todoglobalid/ent/gql_pagination.go @@ -292,7 +292,7 @@ func (bp *BillProductQuery) Paginate( } conn := &BillProductConnection{Edges: []*BillProductEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := bp.Clone() @@ -590,7 +590,7 @@ func (c *CategoryQuery) Paginate( } conn := &CategoryConnection{Edges: []*CategoryEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := c.Clone() @@ -981,7 +981,7 @@ func (f *FriendshipQuery) Paginate( } conn := &FriendshipConnection{Edges: []*FriendshipEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := f.Clone() @@ -1266,7 +1266,7 @@ func (gr *GroupQuery) Paginate( } conn := &GroupConnection{Edges: []*GroupEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := gr.Clone() @@ -1515,7 +1515,7 @@ func (otm *OneToManyQuery) Paginate( } conn := &OneToManyConnection{Edges: []*OneToManyEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := otm.Clone() @@ -1811,7 +1811,7 @@ func (pr *ProjectQuery) Paginate( } conn := &ProjectConnection{Edges: []*ProjectEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := pr.Clone() @@ -2109,7 +2109,7 @@ func (t *TodoQuery) Paginate( } conn := &TodoConnection{Edges: []*TodoEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := t.Clone() @@ -2539,7 +2539,7 @@ func (u *UserQuery) Paginate( } conn := &UserConnection{Edges: []*UserEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := u.Clone() @@ -2843,7 +2843,7 @@ func (w *WorkspaceQuery) Paginate( } conn := &OrganizationConnection{Edges: []*OrganizationEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := w.Clone() diff --git a/entgql/internal/todogotype/ent/gql_pagination.go b/entgql/internal/todogotype/ent/gql_pagination.go index c2a6b8a08..a296d72fb 100644 --- a/entgql/internal/todogotype/ent/gql_pagination.go +++ b/entgql/internal/todogotype/ent/gql_pagination.go @@ -290,7 +290,7 @@ func (bp *BillProductQuery) Paginate( } conn := &BillProductConnection{Edges: []*BillProductEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := bp.Clone() @@ -588,7 +588,7 @@ func (c *CategoryQuery) Paginate( } conn := &CategoryConnection{Edges: []*CategoryEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := c.Clone() @@ -961,7 +961,7 @@ func (f *FriendshipQuery) Paginate( } conn := &FriendshipConnection{Edges: []*FriendshipEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := f.Clone() @@ -1210,7 +1210,7 @@ func (gr *GroupQuery) Paginate( } conn := &GroupConnection{Edges: []*GroupEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := gr.Clone() @@ -1459,7 +1459,7 @@ func (pe *PetQuery) Paginate( } conn := &PetConnection{Edges: []*PetEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := pe.Clone() @@ -1757,7 +1757,7 @@ func (t *TodoQuery) Paginate( } conn := &TodoConnection{Edges: []*TodoEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := t.Clone() @@ -2187,7 +2187,7 @@ func (u *UserQuery) Paginate( } conn := &UserConnection{Edges: []*UserEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := u.Clone() diff --git a/entgql/internal/todopulid/ent/gql_pagination.go b/entgql/internal/todopulid/ent/gql_pagination.go index 287718f9f..6db458de0 100644 --- a/entgql/internal/todopulid/ent/gql_pagination.go +++ b/entgql/internal/todopulid/ent/gql_pagination.go @@ -290,7 +290,7 @@ func (bp *BillProductQuery) Paginate( } conn := &BillProductConnection{Edges: []*BillProductEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := bp.Clone() @@ -588,7 +588,7 @@ func (c *CategoryQuery) Paginate( } conn := &CategoryConnection{Edges: []*CategoryEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := c.Clone() @@ -961,7 +961,7 @@ func (f *FriendshipQuery) Paginate( } conn := &FriendshipConnection{Edges: []*FriendshipEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := f.Clone() @@ -1246,7 +1246,7 @@ func (gr *GroupQuery) Paginate( } conn := &GroupConnection{Edges: []*GroupEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := gr.Clone() @@ -1544,7 +1544,7 @@ func (t *TodoQuery) Paginate( } conn := &TodoConnection{Edges: []*TodoEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := t.Clone() @@ -1974,7 +1974,7 @@ func (u *UserQuery) Paginate( } conn := &UserConnection{Edges: []*UserEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := u.Clone() diff --git a/entgql/internal/todouuid/ent/gql_pagination.go b/entgql/internal/todouuid/ent/gql_pagination.go index 0204a0016..16285470d 100644 --- a/entgql/internal/todouuid/ent/gql_pagination.go +++ b/entgql/internal/todouuid/ent/gql_pagination.go @@ -290,7 +290,7 @@ func (bp *BillProductQuery) Paginate( } conn := &BillProductConnection{Edges: []*BillProductEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := bp.Clone() @@ -588,7 +588,7 @@ func (c *CategoryQuery) Paginate( } conn := &CategoryConnection{Edges: []*CategoryEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := c.Clone() @@ -961,7 +961,7 @@ func (f *FriendshipQuery) Paginate( } conn := &FriendshipConnection{Edges: []*FriendshipEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := f.Clone() @@ -1246,7 +1246,7 @@ func (gr *GroupQuery) Paginate( } conn := &GroupConnection{Edges: []*GroupEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := gr.Clone() @@ -1544,7 +1544,7 @@ func (t *TodoQuery) Paginate( } conn := &TodoConnection{Edges: []*TodoEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := t.Clone() @@ -1974,7 +1974,7 @@ func (u *UserQuery) Paginate( } conn := &UserConnection{Edges: []*UserEdge{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := u.Clone() diff --git a/entgql/template/pagination.tmpl b/entgql/template/pagination.tmpl index 6a7a96a8b..69be38dac 100644 --- a/entgql/template/pagination.tmpl +++ b/entgql/template/pagination.tmpl @@ -629,7 +629,7 @@ func ({{ $r }} *{{ $name }}) ToEdge(order *{{ $order }}) *{{ $edge }} { {{- /* Ensure the "edges" field is marshaled as "[]" in case it is empty. */}} conn := &{{ $conn }}{Edges: []*{{ $edge }}{}} ignoredEdges := !hasCollectedField(ctx, edgesField) - if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + if hasCollectedField(ctx, totalCountField) { hasPagination := after != nil || first != nil || before != nil || last != nil if hasPagination || ignoredEdges { c := {{ $r }}.Clone()