Opened 8 years ago
Closed 8 years ago
#36602 closed enhancement (fixed)
Improvement to redirect_canonical with category permalink
Reported by: | spacedmonkey | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 4.6 | Priority: | normal |
Severity: | normal | Version: | 3.0 |
Component: | Canonical | Keywords: | has-patch commit dev-reviewed |
Focuses: | Cc: |
Description
If you are using category in permalink, the redirect_canonical calls wp_get_object_terms get categories on the current post. As wp_get_object_terms is not cached, it results in an sql query. This is a performance hit for sites using object caching. get_the_terms should be used instead.
Attachments (2)
Change History (15)
#1
@
8 years ago
- Milestone changed from Awaiting Review to 4.6
- Owner set to boonebgorges
- Status changed from new to accepted
#5
@
8 years ago
@boonebgorges @spacedmonkey recommend you back this change out. The in_array will always be false. This has a breaking impact on /embed/ endpoints when sites have %category% in their permalink structure.
Alternative patch attached if you want to use it to fix the original issue.
#6
@
8 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
@cmillerdev Can you explain why the in_array()
check fails? Does this have something to do with object identity?
Your fix seems OK to me (has_term()
falls back to is_object_in_term()
, which checks the object cache) but we need a test to demonstrate the failure.
#7
@
8 years ago
@boonebgorges yes it's because it's checking for an object in an array of objects. You could change it to check for the term by ID etc, but has_term()
seemed much simpler. Test should be easy enough, I'm not writing it though, I want nothing to do with that horrendous function! I'm just reporting the issue. Feel free to use that patch, or not, up to you.
Cheers
#9
@
8 years ago
- Keywords dev-feedback added
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening for 4.6. Can I get a review of [37262] from @ocean90, @wonderboymusic, or @dd32 ?
Thanks for the patch. This looks like a good fix. We have zero test coverage for this kind of rewrite, so I'm going add it before making the change.