Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Without enforcer.loadPolicy() Casbin behave unpredictably on mass updates. #463

Open
mdg-mdrozd opened this issue Nov 10, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@mdg-mdrozd
Copy link

In our ephemeral environments, we reconstruct permissions by frequently invoking methods like enforcer.removePolicy() and enforcer.removeGroupingPolicy() thousands of times. However, each change necessitates a call to enforcer.loadPolicy(). This is increasingly problematic as the service gets progressively burdened with the growing number of policies to reload with each update, ultimately leading to service downtime.

enforcer is setup as follows:

export const casbinProviders = [
  {
    provide: PROVIDER_CASBIN_ENFORCER,
    useFactory: async (dataSource: DataSource) => {
      const adapter = await TypeORMAdapter.newAdapter({ connection: dataSource });
      const enforcer = await newEnforcer(newModelFromString(PERMISSIONS_MODEL), adapter);
      await enforcer.addFunction('isMatch', casbinIsMatch);
      await enforcer.addFunction('includes', casbinIncludes);
      await enforcer.loadPolicy();
      await enforcer.enableAutoSave(true);
      return enforcer;
    },
    inject: [getDataSourceToken()]
  }
];

In our production environment, the substantial number of policies we manage also poses a significant challenge. The frequent use of methods like enforcer.removePolicy() and enforcer.removeGroupingPolicy(), followed by enforcer.loadPolicy() after each modification, is proving to be problematic. As the number of policies grows, these operations increasingly strain the server during normal usage, leading to severe performance issues and potential service disruptions.

@casbin-bot
Copy link
Member

@nodece @Shivansh-yadav13

@casbin-bot casbin-bot added the enhancement New feature or request label Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

No branches or pull requests

3 participants