summaryrefslogtreecommitdiffstats
path: root/models/project/project.go
diff options
context:
space:
mode:
authoryp05327 <576951401@qq.com>2023-02-24 14:18:52 +0900
committerGitHub <noreply@github.com>2023-02-24 13:18:52 +0800
commit5b87c05a95a3eab1cf7f9a9f23052fee9eedd9ac (patch)
tree2ab60e33e5961b8d5a2774ff8c5127f1ac76c559 /models/project/project.go
parent0bc8bb3cc4f003e70bfee75863b74c2243c6d23c (diff)
downloadgitea-5b87c05a95a3eab1cf7f9a9f23052fee9eedd9ac.tar.gz
gitea-5b87c05a95a3eab1cf7f9a9f23052fee9eedd9ac.zip
improve FindProjects (#23085)
I found `FindAndCount` which can `Find` and `Count` in the same time Maybe it is better to use it in `FindProjects` --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'models/project/project.go')
-rw-r--r--models/project/project.go13
1 files changed, 3 insertions, 10 deletions
diff --git a/models/project/project.go b/models/project/project.go
index 931ef44675..46b5c07c42 100644
--- a/models/project/project.go
+++ b/models/project/project.go
@@ -217,16 +217,8 @@ func CountProjects(ctx context.Context, opts SearchOptions) (int64, error) {
// FindProjects returns a list of all projects that have been created in the repository
func FindProjects(ctx context.Context, opts SearchOptions) ([]*Project, int64, error) {
- e := db.GetEngine(ctx)
+ e := db.GetEngine(ctx).Where(opts.toConds())
projects := make([]*Project, 0, setting.UI.IssuePagingNum)
- cond := opts.toConds()
-
- count, err := e.Where(cond).Count(new(Project))
- if err != nil {
- return nil, 0, fmt.Errorf("Count: %w", err)
- }
-
- e = e.Where(cond)
if opts.Page > 0 {
e = e.Limit(setting.UI.IssuePagingNum, (opts.Page-1)*setting.UI.IssuePagingNum)
@@ -243,7 +235,8 @@ func FindProjects(ctx context.Context, opts SearchOptions) ([]*Project, int64, e
e.Asc("created_unix")
}
- return projects, count, e.Find(&projects)
+ count, err := e.FindAndCount(&projects)
+ return projects, count, err
}
// NewProject creates a new Project