-
-
Notifications
You must be signed in to change notification settings - Fork 874
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
perf(laravel): Caching tables and indexes to avoid multiple queries #6744
Closed
amermchaudhary
wants to merge
6
commits into
api-platform:4.0
from
amermchaudhary:optimize-model-metadata
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b766203
perf(laravel): Caching tables and indexes to avoid multiple queries
amermchaudhary cc206e8
perf(laravel) Updates WorkbenchServiceProvider to use null for the de…
amermchaudhary 898ab51
perf(laravel): making phpstan happy
amermchaudhary b6068fc
perf(laravel) fixing the return type for phpstan
amermchaudhary 618785a
perf(laravel): changing the return type for phpstan
amermchaudhary a23ebcc
perf(laravel): making phpstan happier
amermchaudhary File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting change, note also #6735. We already have a cache layer so that this isn't called more then once per metadata computation in production mode.
This cache is stored in memory ? File ? How do you make sure it's not stale ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@soyuka the storage engine of the cache is configurable from laravel's cache config in the file
config/cache.php
. You can use any cache driver (file, database, redis, memcached, etc) and the second argument to the function[5, 10]
basically tells laravel that the cache is only good for 5 seconds and between 5 to 10 seconds period refresh the cached value automatically so it'll only be at max 5 to 10 seconds old.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@soyuka I logged all the queries and saw multiple calls to the information_schema table for the same table's columns and data and thats why I added this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@soyuka in terms of making sure it is not stale:
https://laravel.com/docs/11.x/cache#swr
But as you pointed out, in production this is not called because it cached when calling the
optimize
function (or after the 1st request to the endpoint), so this would apply only to development machines, im not quite sure if or why it would be needed there.@amermchaudhary Are you running into this issue on a production setup or on your development system?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes @amermchaudhary it's running multiple time on a development environment, but if you set debug to
false
metadata gets cached. I'm not a huge fan of multi-layer caching as it's hard to debug when it fails.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh I was checking on my development system. I didn't know that it was being cached on a production system. In that case we should close this PR. It's not necessary!!