1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2025-08-03 00:45:22 +02:00

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>
This commit is contained in:
Lunny Xiao 2024-01-15 10:19:25 +08:00 committed by GitHub
parent e5313248a8
commit 70c4aad8e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 305 additions and 238 deletions

View file

@ -111,7 +111,7 @@ type FindRepoArchiversOption struct {
OlderThan time.Duration
}
func (opts FindRepoArchiversOption) toConds() builder.Cond {
func (opts FindRepoArchiversOption) ToConds() builder.Cond {
cond := builder.NewCond()
if opts.OlderThan > 0 {
cond = cond.And(builder.Lt{"created_unix": time.Now().Add(-opts.OlderThan).Unix()})
@ -119,15 +119,8 @@ func (opts FindRepoArchiversOption) toConds() builder.Cond {
return cond
}
// FindRepoArchives find repo archivers
func FindRepoArchives(ctx context.Context, opts FindRepoArchiversOption) ([]*RepoArchiver, error) {
archivers := make([]*RepoArchiver, 0, opts.PageSize)
start, limit := opts.GetSkipTake()
err := db.GetEngine(ctx).Where(opts.toConds()).
Asc("created_unix").
Limit(limit, start).
Find(&archivers)
return archivers, err
func (opts FindRepoArchiversOption) ToOrders() string {
return "created_unix ASC"
}
// SetArchiveRepoState sets if a repo is archived