Laravel Passport comes with repositories for the underlying oauth2-server that result in multiple queries to retrieve the same exact object from the database in a single request. With a good database engine this will have a small impact in the range of milliseconds but this is still unacceptable and should be avoided if possible.
With a typical Passport token authenticated request you will see that the token is retrieved 3 times and the client is retrieved twice.
This might be patched in future Laravel Passport releases, but until that time you can install this package.
This package replaces the client and token repositories with ones that memoize the results of certain calls that perform database queries to remove the duplicate queries.
It's safe to use with Laravel Octane since we make sure that the memoize cache is cleared after each request to prevent stale caches.
And not a PR to Laravel Passport? This was attempted (although not a perfect solution yet) in the past but it was decided to not be changed so this package was created as an alternative. See also this pinned issue for more information and another package if you are looking for an alternative solution.
composer require stayallive/laravel-passport-memoized
You should only have to install this package to benefit, unless you have disable package auto discovery, in that case you will need to add the service provider to
your config/app.php
manually.
If you discover a security vulnerability within this package, please send an e-mail to Alex Bouma at [email protected]
. All security vulnerabilities will be swiftly
addressed.
This package is open-sourced software licensed under the MIT license.