Optimize the non-cached clipboard to only fetch relevant abilities #276
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Current situation
Currently, the clipboard will always fetch all abilities when checking anything at the gate. The abilities are cached (by default for the current request, but can also be cached forever by calling the
cache()
method onBouncer
).This is great if you only use a handful of abilities, since pulling them all down once and then running all checks against that set of abilities is very efficient.
However, if you use abilities for specific models, like:
...you can quickly end up with users who have hundreds of abilities. Pulling down all abilities to run a single check becomes a performance penalty instead of an improvement.
Improvement in this PR
With this PR, the non-caching clipboard now only pulls down the single relevant ability for the given check. So if you configure Bouncer not to cache your queries:
Bouncer::dontCache();
...it now will no longer pull all abilities from the database at once.
After merging this and having people try it out, I plan to create an additional caching clipboard based on this one, that only caches the results of the checks at the gate.
References #263