Speed up object.DoMigration()

This commit is contained in:
Yang Luo 2023-06-01 22:25:19 +08:00
parent 9147225956
commit 5349fa7ff3
2 changed files with 7 additions and 11 deletions

View File

@ -22,20 +22,12 @@ import (
type Migrator_1_314_0_PR_1841 struct{}
func (*Migrator_1_314_0_PR_1841) IsMigrationNeeded() bool {
users := []*User{}
err := adapter.Engine.Table("user").Find(&users)
count, err := adapter.Engine.Where("password_type=?", "").Count(&User{})
if err != nil {
return false
panic(err)
}
for _, u := range users {
if u.PasswordType != "" {
return false
}
}
return true
return count > 100
}
func (*Migrator_1_314_0_PR_1841) DoMigration() *migrate.Migration {

View File

@ -554,6 +554,10 @@ func AddUser(user *User) (bool, error) {
return false, nil
}
if user.PasswordType == "" && organization.PasswordType != "" {
user.PasswordType = organization.PasswordType
}
user.UpdateUserPassword(organization)
err = user.UpdateUserHash()