1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Merge db.Iterate and IterateObjects (#21641)

These two functions are similiar, merge them.
This commit is contained in:
Lunny Xiao
2022-10-31 23:51:14 +08:00
committed by GitHub
parent 4ae3f76217
commit 9a70a12a34
12 changed files with 77 additions and 51 deletions

View File

@@ -96,7 +96,7 @@ func DeleteAvatar(repo *repo_model.Repository) error {
// RemoveRandomAvatars removes the randomly generated avatars that were created for repositories
func RemoveRandomAvatars(ctx context.Context) error {
return db.IterateObjects(ctx, func(repository *repo_model.Repository) error {
return db.Iterate(ctx, nil, func(ctx context.Context, repository *repo_model.Repository) error {
select {
case <-ctx.Done():
return db.ErrCancelledf("before random avatars removed for %s", repository.FullName())

View File

@@ -29,10 +29,8 @@ func GitFsck(ctx context.Context, timeout time.Duration, args []git.CmdArg) erro
if err := db.Iterate(
ctx,
new(repo_model.Repository),
builder.Expr("id>0 AND is_fsck_enabled=?", true),
func(idx int, bean interface{}) error {
repo := bean.(*repo_model.Repository)
func(ctx context.Context, repo *repo_model.Repository) error {
select {
case <-ctx.Done():
return db.ErrCancelledf("before fsck of %s", repo.FullName())
@@ -64,10 +62,8 @@ func GitGcRepos(ctx context.Context, timeout time.Duration, args ...git.CmdArg)
if err := db.Iterate(
ctx,
new(repo_model.Repository),
builder.Gt{"id": 0},
func(idx int, bean interface{}) error {
repo := bean.(*repo_model.Repository)
func(ctx context.Context, repo *repo_model.Repository) error {
select {
case <-ctx.Done():
return db.ErrCancelledf("before GC of %s", repo.FullName())
@@ -113,10 +109,8 @@ func gatherMissingRepoRecords(ctx context.Context) ([]*repo_model.Repository, er
repos := make([]*repo_model.Repository, 0, 10)
if err := db.Iterate(
ctx,
new(repo_model.Repository),
builder.Gt{"id": 0},
func(idx int, bean interface{}) error {
repo := bean.(*repo_model.Repository)
func(ctx context.Context, repo *repo_model.Repository) error {
select {
case <-ctx.Done():
return db.ErrCancelledf("during gathering missing repo records before checking %s", repo.FullName())

View File

@@ -25,10 +25,8 @@ func SyncRepositoryHooks(ctx context.Context) error {
if err := db.Iterate(
ctx,
new(repo_model.Repository),
builder.Gt{"id": 0},
func(idx int, bean interface{}) error {
repo := bean.(*repo_model.Repository)
func(ctx context.Context, repo *repo_model.Repository) error {
select {
case <-ctx.Done():
return db.ErrCancelledf("before sync repository hooks for %s", repo.FullName())