Changelog - 2026-07-20
Casbin Single-Wave Extraction
Enhancement Behavior Change Bug FixIn one line. ScopedCasbinAdapter.loadFilteredPolicy now issues four statements in one Promise.all instead of two sequential waves, and holds no cache.
What changed
- One wave, four statements. A single recursive query,
queryPrincipalPolicy, resolves the principal's role closure in SQL. It runs alongsidequeryResourceInherits,queryActionInheritsandqueryDomainInherits, which are unchanged. - Narrower
role_inheritsoutput. Only edges reachable from the principal's assigned roles are emitted. Matching behaves the same, and each user's line payload is smaller. - A grant with a missing target is no longer silent. The permission join is now a
LEFT JOIN. A grant whose targetPermissionis missing or soft-deleted is returned, andbuildGrantLineslogs an error naming the subject before skipping it. The grant still does not apply. - The structural cache is gone. The
structuralCacheconstructor option,invalidateStructuralCache(), and the 60-second staleness window are removed.
Who is affected
- Every consumer of
ScopedCasbinAdapter. If you passedstructuralCacheto the constructor, drop the option. - Apps that called
invalidateStructuralCache()after a migration. Delete the call. Nothing is cached, so there is nothing to invalidate. - Operators of the
PolicyDefinitiontable. The framework does not create indexes, so create the ones below.
Details
Required indexes on PolicyDefinition:
| Index | Serves |
|---|---|
(variant, subject_type, subject_id) | queryPrincipalPolicy's anchor term and direct-edge branch |
(variant, subject_id) | queryPrincipalPolicy's recursive-term join and role-grant branch |
(variant), or per-variant partial indexes | queryResourceInherits, queryActionInherits, queryDomainInherits |
Without them these queries fall back to a sequential scan.