-
Notifications
You must be signed in to change notification settings - Fork 798
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
Add check for local files before processing post images in Photon #13103
Conversation
Thank you for the great PR description! When this PR is ready for review, please apply the Scheduled Jetpack release: September 3, 2019. |
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.
It seems to work in my tests. Thank you for adding tests as well. I would have 2 minor remarks.
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.
I know I'm probably overthinking it, but can we go back to only getting upload dir details once per image? Currently with this code we're doing it three times. And while the code only runs the "lightweight" version that doesn't refresh the upload folder every time, it still runs through filters that may be set on the upload dir location. We will be triggering these filters three times more now with this change.
Can we get rid of the is_local_upload
method, store the upload folder data as before and just run strpos
inside if conditions?
@zinigor That makes sense. Considering that we're only using this in only 2 places in the class right now, the new |
Whoa, sorry for such a delay with the response, @hanifn . Yeah, sure, if we can reduce the number of calls even more, I'm all for that. Can you please make it, as well as rebase the code so that it wouldn't conflict? I'm happy to take a look and test again. |
Co-Authored-By: Jeremy Herve <jeremy@jeremy.hu>
using is_local_upload results in an extra call to wp_get_upload_dir() every image.
04048de
to
a84daa0
Compare
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.
Thanks, sorry it took me so long to review this one!
* Changelog: initial set of changes for 7.8 * Changelog: add #13310 * Changelog: add #13103 * Changelog: add #13426 * Changelog: add #13389 * Changelog: add #13449 * Changelog: add #13461 * Changelog: add #13460 * Changelog: add #13441 * Changelog: add #13454 * Changelog: add #13457 * Changelog: add #13425 * Changelog: add #13473 * Changelog: add #13355 * Changelog: add #13451 * Changelog: add #13358 * Changelog: add #13464 * Changelog: add #13416 * Changelog: add #13494 * Changelog: add #13465 * Changelog: add #13424 * Changelog: add #13432 * Changelog: add #13471 * Changelog: add 7.7.2 entry * Changelog: add #13446 * Add more testing elements
* Changelog: initial set of changes for 7.8 * Changelog: add #13310 * Changelog: add #13103 * Changelog: add #13426 * Changelog: add #13389 * Changelog: add #13449 * Changelog: add #13461 * Changelog: add #13460 * Changelog: add #13441 * Changelog: add #13454 * Changelog: add #13457 * Changelog: add #13425 * Changelog: add #13473 * Changelog: add #13355 * Changelog: add #13451 * Changelog: add #13358 * Changelog: add #13464 * Changelog: add #13416 * Changelog: add #13494 * Changelog: add #13465 * Changelog: add #13424 * Changelog: add #13432 * Changelog: add #13471 * Changelog: add 7.7.2 entry * Changelog: add #13446 * Add more testing elements
Summary
In
Jetpack_Photon::filter_the_content
, the call tostrip_image_dimensions_maybe
is outside theif
clause that checks for local uploads. This is problematic becausestrip_image_dimensions_maybe
only checks if the filename has the image dimensions string, e.g.:300x300
, and then callsfile_exists
on this file after removing the image dimensions and prepending thebasedir
. If a file is hosted externally, like on a CDN, the call tofile_exists
will only return false. Additionally, if the site is using a custom Stream wrapper implementation to upload files to the CDN, thesefile_exists
calls results in a lot of requests to the CDN that returns404
status. This means those requests are uncached and would slow down the site load times.Changes proposed in this Pull Request:
strip_image_dimensions_maybe
.Testing instructions:
Note: Tested on a site hosted on VIP Go.
-300x300.jpg
.404
response.Proposed changelog entry for your changes: