mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 20:50:19 +08:00
feat: add batchSize to conf (#1120)
This commit is contained in:
@ -30,7 +30,7 @@ func InitAuthz() {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
tableNamePrefix := conf.GetConfigString("tableNamePrefix")
|
tableNamePrefix := conf.GetConfigString("tableNamePrefix")
|
||||||
a, err := xormadapter.NewAdapterWithTableName(conf.GetConfigString("driverName"), conf.GetBeegoConfDataSourceName()+conf.GetConfigString("dbName"), "casbin_rule", tableNamePrefix, true)
|
a, err := xormadapter.NewAdapterWithTableName(conf.GetConfigString("driverName"), conf.GetConfigDataSourceName()+conf.GetConfigString("dbName"), "casbin_rule", tableNamePrefix, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -18,3 +18,4 @@ logPostOnly = true
|
|||||||
origin =
|
origin =
|
||||||
staticBaseUrl = "https://cdn.casbin.org"
|
staticBaseUrl = "https://cdn.casbin.org"
|
||||||
isDemoMode = false
|
isDemoMode = false
|
||||||
|
batchSize = 100
|
||||||
|
33
conf/conf.go
33
conf/conf.go
@ -24,6 +24,19 @@ import (
|
|||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
// this array contains the beego configuration items that may be modified via env
|
||||||
|
presetConfigItems := []string{"httpport", "appname"}
|
||||||
|
for _, key := range presetConfigItems {
|
||||||
|
if value, ok := os.LookupEnv(key); ok {
|
||||||
|
err := beego.AppConfig.Set(key, value)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func GetConfigString(key string) string {
|
func GetConfigString(key string) string {
|
||||||
if value, ok := os.LookupEnv(key); ok {
|
if value, ok := os.LookupEnv(key); ok {
|
||||||
return value
|
return value
|
||||||
@ -55,17 +68,7 @@ func GetConfigInt64(key string) (int64, error) {
|
|||||||
return num, err
|
return num, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func GetConfigDataSourceName() string {
|
||||||
// this array contains the beego configuration items that may be modified via env
|
|
||||||
presetConfigItems := []string{"httpport", "appname"}
|
|
||||||
for _, key := range presetConfigItems {
|
|
||||||
if value, ok := os.LookupEnv(key); ok {
|
|
||||||
beego.AppConfig.Set(key, value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetBeegoConfDataSourceName() string {
|
|
||||||
dataSourceName := GetConfigString("dataSourceName")
|
dataSourceName := GetConfigString("dataSourceName")
|
||||||
|
|
||||||
runningInDocker := os.Getenv("RUNNING_IN_DOCKER")
|
runningInDocker := os.Getenv("RUNNING_IN_DOCKER")
|
||||||
@ -84,3 +87,11 @@ func GetBeegoConfDataSourceName() string {
|
|||||||
func IsDemoMode() bool {
|
func IsDemoMode() bool {
|
||||||
return strings.ToLower(GetConfigString("isDemoMode")) == "true"
|
return strings.ToLower(GetConfigString("isDemoMode")) == "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetConfigBatchSize() int {
|
||||||
|
res, err := strconv.Atoi(GetConfigString("batchSize"))
|
||||||
|
if err != nil {
|
||||||
|
res = 100
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
@ -43,7 +43,7 @@ func InitConfig() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func InitAdapter(createDatabase bool) {
|
func InitAdapter(createDatabase bool) {
|
||||||
adapter = NewAdapter(conf.GetConfigString("driverName"), conf.GetBeegoConfDataSourceName(), conf.GetConfigString("dbName"))
|
adapter = NewAdapter(conf.GetConfigString("driverName"), conf.GetConfigDataSourceName(), conf.GetConfigString("dbName"))
|
||||||
if createDatabase {
|
if createDatabase {
|
||||||
adapter.CreateDatabase()
|
adapter.CreateDatabase()
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ func getEnforcer(permission *Permission) *casbin.Enforcer {
|
|||||||
tableName = permission.Adapter
|
tableName = permission.Adapter
|
||||||
}
|
}
|
||||||
tableNamePrefix := conf.GetConfigString("tableNamePrefix")
|
tableNamePrefix := conf.GetConfigString("tableNamePrefix")
|
||||||
adapter, err := xormadapter.NewAdapterWithTableName(conf.GetConfigString("driverName"), conf.GetBeegoConfDataSourceName()+conf.GetConfigString("dbName"), tableName, tableNamePrefix, true)
|
adapter, err := xormadapter.NewAdapterWithTableName(conf.GetConfigString("driverName"), conf.GetConfigDataSourceName()+conf.GetConfigString("dbName"), tableName, tableNamePrefix, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/casdoor/casdoor/conf"
|
||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
"github.com/duo-labs/webauthn/webauthn"
|
"github.com/duo-labs/webauthn/webauthn"
|
||||||
"xorm.io/core"
|
"xorm.io/core"
|
||||||
@ -487,7 +488,7 @@ func AddUsers(users []*User) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AddUsersInBatch(users []*User) bool {
|
func AddUsersInBatch(users []*User) bool {
|
||||||
batchSize := 1000
|
batchSize := conf.GetConfigBatchSize()
|
||||||
|
|
||||||
if len(users) == 0 {
|
if len(users) == 0 {
|
||||||
return false
|
return false
|
||||||
|
Reference in New Issue
Block a user