From a1230f44dc4dfa264b9fc4207aed04a0a5c17f9b Mon Sep 17 00:00:00 2001 From: Selene Date: Thu, 14 Oct 2021 09:51:32 +0200 Subject: [PATCH] Fix user's total count in search (#40415) --- pkg/services/sqlstore/user.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/services/sqlstore/user.go b/pkg/services/sqlstore/user.go index af0474867fc..07fa9fe3f0e 100644 --- a/pkg/services/sqlstore/user.go +++ b/pkg/services/sqlstore/user.go @@ -654,6 +654,18 @@ func SearchUsers(ctx context.Context, query *models.SearchUsersQuery) error { countSess.Where(strings.Join(whereConditions, " AND "), whereParams...) } + for _, filter := range query.Filters { + if jc := filter.JoinCondition(); jc != nil { + countSess.Join(jc.Operator, jc.Table, jc.Params) + } + if ic := filter.InCondition(); ic != nil { + countSess.In(ic.Condition, ic.Params) + } + if wc := filter.WhereCondition(); wc != nil { + countSess.Where(wc.Condition, wc.Params) + } + } + count, err := countSess.Count(&user) query.Result.TotalCount = count