mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 02:35:49 +08:00
Fix batch methods like AddUsersInBatch()
This commit is contained in:
parent
23c4fd8183
commit
d06d7c5c09
@ -15,6 +15,7 @@
|
|||||||
package object
|
package object
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/casdoor/casdoor/conf"
|
"github.com/casdoor/casdoor/conf"
|
||||||
@ -217,16 +218,15 @@ func AddPermissionsInBatch(permissions []*Permission) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
affected := false
|
affected := false
|
||||||
for i := 0; i < (len(permissions)-1)/batchSize+1; i++ {
|
for i := 0; i < len(permissions); i += batchSize {
|
||||||
start := i * batchSize
|
start := i
|
||||||
end := (i + 1) * batchSize
|
end := i + batchSize
|
||||||
if end > len(permissions) {
|
if end > len(permissions) {
|
||||||
end = len(permissions)
|
end = len(permissions)
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp := permissions[start:end]
|
tmp := permissions[start:end]
|
||||||
// TODO: save to log instead of standard output
|
fmt.Printf("The syncer adds permissions: [%d - %d]\n", start, end)
|
||||||
// fmt.Printf("Add Permissions: [%d - %d].\n", start, end)
|
|
||||||
if AddPermissions(tmp) {
|
if AddPermissions(tmp) {
|
||||||
affected = true
|
affected = true
|
||||||
}
|
}
|
||||||
|
@ -82,5 +82,6 @@ func UploadPermissions(owner string, path string) (bool, error) {
|
|||||||
if len(newPermissions) == 0 {
|
if len(newPermissions) == 0 {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return AddPermissionsInBatch(newPermissions), nil
|
return AddPermissionsInBatch(newPermissions), nil
|
||||||
}
|
}
|
||||||
|
@ -208,16 +208,15 @@ func AddRolesInBatch(roles []*Role) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
affected := false
|
affected := false
|
||||||
for i := 0; i < (len(roles)-1)/batchSize+1; i++ {
|
for i := 0; i < len(roles); i += batchSize {
|
||||||
start := i * batchSize
|
start := i
|
||||||
end := (i + 1) * batchSize
|
end := i + batchSize
|
||||||
if end > len(roles) {
|
if end > len(roles) {
|
||||||
end = len(roles)
|
end = len(roles)
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp := roles[start:end]
|
tmp := roles[start:end]
|
||||||
// TODO: save to log instead of standard output
|
fmt.Printf("The syncer adds roles: [%d - %d]\n", start, end)
|
||||||
// fmt.Printf("Add users: [%d - %d].\n", start, end)
|
|
||||||
if AddRoles(tmp) {
|
if AddRoles(tmp) {
|
||||||
affected = true
|
affected = true
|
||||||
}
|
}
|
||||||
|
@ -68,5 +68,6 @@ func UploadRoles(owner string, path string) (bool, error) {
|
|||||||
if len(newRoles) == 0 {
|
if len(newRoles) == 0 {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return AddRolesInBatch(newRoles), nil
|
return AddRolesInBatch(newRoles), nil
|
||||||
}
|
}
|
||||||
|
@ -122,6 +122,7 @@ func (syncer *Syncer) syncUsers() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = AddUsersInBatch(newUsers)
|
_, err = AddUsersInBatch(newUsers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -196,7 +196,10 @@ func RunSyncUsersJob() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, syncer := range syncers {
|
for _, syncer := range syncers {
|
||||||
addSyncerJob(syncer)
|
err = addSyncerJob(syncer)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(time.Duration(1<<63 - 1))
|
time.Sleep(time.Duration(1<<63 - 1))
|
||||||
|
@ -717,16 +717,15 @@ func AddUsersInBatch(users []*User) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
affected := false
|
affected := false
|
||||||
for i := 0; i < (len(users)-1)/batchSize+1; i++ {
|
for i := 0; i < len(users); i += batchSize {
|
||||||
start := i * batchSize
|
start := i
|
||||||
end := (i + 1) * batchSize
|
end := i + batchSize
|
||||||
if end > len(users) {
|
if end > len(users) {
|
||||||
end = len(users)
|
end = len(users)
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp := users[start:end]
|
tmp := users[start:end]
|
||||||
// TODO: save to log instead of standard output
|
fmt.Printf("The syncer adds users: [%d - %d]\n", start, end)
|
||||||
// fmt.Printf("Add users: [%d - %d].\n", start, end)
|
|
||||||
if ok, err := AddUsers(tmp); err != nil {
|
if ok, err := AddUsers(tmp); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
} else if ok {
|
} else if ok {
|
||||||
|
@ -144,5 +144,6 @@ func UploadUsers(owner string, path string) (bool, error) {
|
|||||||
if len(newUsers) == 0 {
|
if len(newUsers) == 0 {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return AddUsersInBatch(newUsers)
|
return AddUsersInBatch(newUsers)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user