diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2024-01-15 10:19:25 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-15 02:19:25 +0000 |
commit | 70c4aad8e1cbc46b049b015dcd6f2e5be5a69e72 (patch) | |
tree | 5c9f049437c1a84a402aeef3be0cb4b95dea667e /models/repo/fork.go | |
parent | e5313248a8ed967a915f072d3991b6d046badf02 (diff) | |
download | gitea-70c4aad8e1cbc46b049b015dcd6f2e5be5a69e72.tar.gz gitea-70c4aad8e1cbc46b049b015dcd6f2e5be5a69e72.zip |
Move more functions to db.Find (#28419)
Following #28220
This PR move more functions to use `db.Find`.
---------
Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'models/repo/fork.go')
-rw-r--r-- | models/repo/fork.go | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/models/repo/fork.go b/models/repo/fork.go index 6be6ebc3f5..07cd31c269 100644 --- a/models/repo/fork.go +++ b/models/repo/fork.go @@ -56,13 +56,16 @@ func GetUserFork(ctx context.Context, repoID, userID int64) (*Repository, error) // GetForks returns all the forks of the repository func GetForks(ctx context.Context, repo *Repository, listOptions db.ListOptions) ([]*Repository, error) { + sess := db.GetEngine(ctx) + + var forks []*Repository if listOptions.Page == 0 { - forks := make([]*Repository, 0, repo.NumForks) - return forks, db.GetEngine(ctx).Find(&forks, &Repository{ForkID: repo.ID}) + forks = make([]*Repository, 0, repo.NumForks) + } else { + forks = make([]*Repository, 0, listOptions.PageSize) + sess = db.SetSessionPagination(sess, &listOptions) } - sess := db.GetPaginatedSession(&listOptions) - forks := make([]*Repository, 0, listOptions.PageSize) return forks, sess.Find(&forks, &Repository{ForkID: repo.ID}) } |