Skip to content

perf(auth): memoize current authenticatable#2144

Open
xHeaven wants to merge 1 commit into
tempestphp:3.xfrom
xHeaven:fix/auth-current-cache
Open

perf(auth): memoize current authenticatable#2144
xHeaven wants to merge 1 commit into
tempestphp:3.xfrom
xHeaven:fix/auth-current-cache

Conversation

@xHeaven
Copy link
Copy Markdown
Member

@xHeaven xHeaven commented Jun 2, 2026

This PR memoizes the current authenticatable within SessionAuthenticator. Previously, each call to current() re-resolved the authenticated model from the database, which caused repeated identical queries during authorization checks that rely on the implicit current subject. The authenticator now caches the resolved authenticatable for the current session identity and invalidates that cache when the identity changes, when a new user is authenticated, or when the session is deauthenticated.

@xHeaven xHeaven requested a review from innocenzi as a code owner June 2, 2026 13:39
@xHeaven xHeaven force-pushed the fix/auth-current-cache branch from afb5438 to a54d529 Compare June 2, 2026 14:04

public const string AUTHENTICATABLE_CLASS = '#authenticatable:class';

private bool $currentResolved = false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should be able to get rid of this and only use $current, since when $current is not null, $currentResolved is true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants