Skip to content
This repository has been archived by the owner on Jul 5, 2019. It is now read-only.

The performance of SavePolicy() is poor. #3

Open
hsluoyz opened this issue Jun 17, 2018 · 1 comment
Open

The performance of SavePolicy() is poor. #3

hsluoyz opened this issue Jun 17, 2018 · 1 comment

Comments

@hsluoyz
Copy link

hsluoyz commented Jun 17, 2018

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.

@silversquirl
Copy link

It looks like this was "fixed" in 9892155, with the side-effect of adding potential SQL injection. Please can this change be reverted so that this adapter is safe to use again.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants