From ee9950ec2f2811896918e74540fc6c3f40918daf Mon Sep 17 00:00:00 2001 From: Unknwon Date: Tue, 18 Jul 2017 22:07:40 -0400 Subject: [PATCH] explore: fix total repository number and page number do not match (#4441) Because in the final repository list we use Distinct to remove duplicates, but didn't do so when count total number of repositories. --- models/repo.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/models/repo.go b/models/repo.go index d6205ca53..dd04ac6e0 100644 --- a/models/repo.go +++ b/models/repo.go @@ -1659,9 +1659,8 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos []*Repository, _ int sess.And("repo.owner_id = ?", opts.OwnerID) } - var countSess xorm.Session - countSess = *sess - count, err := countSess.Count(new(Repository)) + // We need all fields (repo.*) in final list but only ID (repo.id) is good enough for counting. + count, err = sess.Clone().Distinct("repo.id").Count(new(Repository)) if err != nil { return nil, 0, fmt.Errorf("Count: %v", err) }