-
Notifications
You must be signed in to change notification settings - Fork 109
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
Prevent optimizing post previews by default #1848
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## trunk #1848 +/- ##
=======================================
Coverage 65.97% 65.98%
=======================================
Files 88 88
Lines 6895 6896 +1
=======================================
+ Hits 4549 4550 +1
Misses 2346 2346
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Thank you! Could you please add a test case to make sure that this condition is working as expected? |
Hi @westonruter, I had tried to add the test case for the same, Could you please check if below is the correct way to add a test case for this?
We can add the above here after this, performance/plugins/optimization-detective/tests/test-optimization.php Lines 284 to 292 in 68c6deb
If yes, I would update the PR with the changes, I can update the test case name as per the standards. I do have run the test locally, by mocking this as Thank You, |
@hbhalodia that mostly looks good, but probably should use |
Hi @westonruter, Thanks for the suggestion. I have one issue, when I try to commit this, Thank You, |
Hi @westonruter, This is now fixed. Updated the PR with the changes and test cases. Thank You, |
@@ -167,6 +167,8 @@ function od_can_optimize_response(): bool { | |||
// > Access to script at '.../detect.js?ver=0.4.1' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. | |||
// So it's better to just avoid attempting to optimize Post Embed responses (which don't need optimization anyway). | |||
is_embed() || | |||
// Skip posts that aren't published yet. | |||
is_preview() || |
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 tried commenting out this line to see if the new test would start to fail as expected, but it still passed. This is because the test's set_up
logic wasn't setting the current user to be able to view the post preview in the first place. When this happens, the $wp_query->posts
loop is then empty. This results in od_get_cache_purge_post_id()
returning null
which as can be seen below also results in this od_can_optimize_response()
function returning false
. So I update the test in e961c37 to explicitly set the current user so that is_preview()
will return true
.
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 @westonruter, for the fix and insights on 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.
Thank you!
Summary
Fixes #1841
Relevant technical choices
is_preview()
inod_can_optimize_response
function to exclude the post/page preview, because it won't make sense to gather the URL metric data for the post that is not yet published.