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

Remove an unnecessary optimisation #8850

Closed
wants to merge 1 commit into from
Closed

Conversation

seanh
Copy link
Contributor

@seanh seanh commented Aug 1, 2024

Remove an unnessary optimisation where
AuthCookieService.verify_cookie() (a method that is only ever called
by CookiePolicy.identity(), and returns the user identity represented
by the request's auth cookie) caches the user object as self._user so
that it can just return it if called again, rather than recomputing it
from the cookie.

This optimisation looks potentially dodgy to me because self._user is
not only set by the verify_cookie() method but also by
create_cookie().

We probably don't need to optimise this but if we do want to optimise it
the right way would be to cache the final return value of the
AuthCookieService.verify_cookie() method (not an intermediate value)
or cache the return value of the higher-level CookiePolicy.identity()
method that calls it.

Remove an unnessary optimisation where
`AuthCookieService.verify_cookie()` (a method that is only ever called
by `CookiePolicy.identity()`, and returns the user identity represented
by the request's auth cookie) caches the user object as `self._user` so
that it can just return it if called again, rather than recomputing it
from the cookie.

This optimisation looks potentially dodgy to me because `self._user` is
not only set by the `verify_cookie()` method but also by
`create_cookie()`.

We probably don't need to optimise this but if we do want to optimise it
the right way would be to cache the final return value of the
`AuthCookieService.verify_cookie()` method (not an intermediate value)
or cache the return value of the higher-level `CookiePolicy.identity()`
method that calls it.
@seanh seanh requested a review from robertknight August 1, 2024 17:53
@seanh seanh closed this Aug 1, 2024
@seanh seanh deleted the remove-unnessary-optimisation branch August 1, 2024 17:56
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.

1 participant