aboutsummaryrefslogtreecommitdiffstats
path: root/services/migrations
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2023-11-24 11:49:41 +0800
committerGitHub <noreply@github.com>2023-11-24 03:49:41 +0000
commitdf1e7d0067bb39913eb681ccc920649884fb1938 (patch)
tree2419feab5c28658adb7f71878df646bdc9bdc50e /services/migrations
parentd24a8223ce1e47a0c9b103aae07f67c3112ca048 (diff)
downloadgitea-df1e7d0067bb39913eb681ccc920649884fb1938.tar.gz
gitea-df1e7d0067bb39913eb681ccc920649884fb1938.zip
Use db.Find instead of writing methods for every object (#28084)
For those simple objects, it's unnecessary to write the find and count methods again and again.
Diffstat (limited to 'services/migrations')
-rw-r--r--services/migrations/update.go13
1 files changed, 7 insertions, 6 deletions
diff --git a/services/migrations/update.go b/services/migrations/update.go
index d466832363..4a49206f82 100644
--- a/services/migrations/update.go
+++ b/services/migrations/update.go
@@ -36,8 +36,7 @@ func updateMigrationPosterIDByGitService(ctx context.Context, tp structs.GitServ
}
const batchSize = 100
- var start int
- for {
+ for page := 0; ; page++ {
select {
case <-ctx.Done():
log.Warn("UpdateMigrationPosterIDByGitService(%s) cancelled", tp.Name())
@@ -45,10 +44,13 @@ func updateMigrationPosterIDByGitService(ctx context.Context, tp structs.GitServ
default:
}
- users, err := user_model.FindExternalUsersByProvider(ctx, user_model.FindExternalUserOptions{
+ users, err := db.Find[user_model.ExternalLoginUser](ctx, user_model.FindExternalUserOptions{
+ ListOptions: db.ListOptions{
+ PageSize: batchSize,
+ Page: page,
+ },
Provider: provider,
- Start: start,
- Limit: batchSize,
+ OrderBy: "login_source_id ASC, external_id ASC",
})
if err != nil {
return err
@@ -70,7 +72,6 @@ func updateMigrationPosterIDByGitService(ctx context.Context, tp structs.GitServ
if len(users) < batchSize {
break
}
- start += len(users)
}
return nil
}