* added chunks of 1000 for deletion of role
This commit is contained in:
lemonScaletech 2024-01-10 12:56:30 +05:30
parent e52164665f
commit 40a0a2fbcc

View File

@ -112,17 +112,29 @@ func updateRoles(ctx context.Context, deletedRoles []string) error {
return err return err
} }
for i := range allData.Users { chunkSize := 1000
roles := utils.DeleteFromArray(allData.Users[i].Roles, deletedRoles) totalUsers := len(allData.Users)
if len(allData.Users[i].Roles) != len(roles) {
updatedValues := map[string]interface{}{ for start := 0; start < totalUsers; start += chunkSize {
"roles": strings.Join(roles, ","), end := start + chunkSize
"updated_at": time.Now().Unix(), if end > totalUsers {
} end = totalUsers
id := []string{allData.Users[i].ID} }
err = db.Provider.UpdateUsers(ctx, updatedValues, id)
if err != nil { chunkUsers := allData.Users[start:end]
return err
for i := range chunkUsers {
roles := utils.DeleteFromArray(chunkUsers[i].Roles, deletedRoles)
if len(chunkUsers[i].Roles) != len(roles) {
updatedValues := map[string]interface{}{
"roles": strings.Join(roles, ","),
"updated_at": time.Now().Unix(),
}
id := []string{chunkUsers[i].ID}
err = db.Provider.UpdateUsers(ctx, updatedValues, id)
if err != nil {
return err
}
} }
} }
} }