stayallive / laravel-passport-memoized
Laravel Passport memoized repositories.
Fund package maintenance!
stayallive
Installs: 9 936
Dependents: 4
Suggesters: 2
Security: 0
Stars: 26
Watchers: 3
Forks: 2
Open Issues: 1
Requires
- php: ^8.0.2
- laravel/framework: ^9|^10|^11
- laravel/passport: ^10|^11|^12
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.14
- laravel/octane: ^1.2|^2
- orchestra/testbench: ^8|^9
- phpunit/phpunit: ^10.0
README
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.
Why a package?
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.
Installation
composer require stayallive/laravel-passport-memoized
Usage
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.
Security Vulnerabilities
If you discover a security vulnerability within this package, please send an e-mail to Alex Bouma at alex+security@bouma.me
. All security vulnerabilities will be swiftly
addressed.
License
This package is open-sourced software licensed under the MIT license.