1
Fork 0

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.
This commit is contained in:
Lunny Xiao 2023-11-24 11:49:41 +08:00 committed by GitHub
parent d24a8223ce
commit df1e7d0067
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
88 changed files with 611 additions and 685 deletions

View file

@ -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
}