A user complained in Twitter that the performance of saving policy to PostgreSQL is poor. See the below code:
|
func (a *Adapter) SavePolicy(model model.Model) error { |
|
a.open() |
|
defer a.close() |
|
|
|
a.dropTable() |
|
a.createTable() |
|
|
|
stm, err := a.db.Prepare("insert into policy values($1, $2, $3, $4, $5, $6, $7)") |
|
if err != nil { |
|
return err |
|
} |
|
defer stm.Close() |
|
|
|
for ptype, ast := range model["p"] { |
|
for _, rule := range ast.Policy { |
|
if err = a.writeTableLine(stm, ptype, rule); err != nil { |
|
return err |
|
} |
|
} |
|
} |
|
|
|
for ptype, ast := range model["g"] { |
|
for _, rule := range ast.Policy { |
|
if err = a.writeTableLine(stm, ptype, rule); err != nil { |
|
return err |
|
} |
|
} |
|
} |
|
return nil |
|
} |
Each Casbin policy rule is inserted into DB separatedly with an insert into, which causes the performance downgrade. Can you fix it by inserting all policy rules in one statement? Thanks.
A user complained in Twitter that the performance of saving policy to PostgreSQL is poor. See the below code:
casbin-postgres-adapter/adapter.go
Lines 162 to 191 in 3a172af
Each Casbin policy rule is inserted into DB separatedly with an
insert into, which causes the performance downgrade. Can you fix it by inserting all policy rules in one statement? Thanks.