Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve FindProjects #23085

Merged
merged 3 commits into from
Feb 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions models/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down