Opened 10 years ago
Closed 10 years ago
#36602 closed enhancement (fixed)
Improvement to redirect_canonical with category permalink
| Reported by: | spacedmonkey | Owned by: | boonebgorges |
|---|---|---|---|
| Priority: | normal | Milestone: | 4.6 |
| Component: | Canonical | Version: | 3.0 |
| Severity: | normal | Keywords: | has-patch commit dev-reviewed |
| Cc: | Focuses: |
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)
#5
@
10 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.
#6
@
10 years ago
- Resolution fixed
- Status closed → 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
@
10 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
@
10 years ago
- Keywords dev-feedback added
- Resolution fixed
- Status closed → reopened
Reopening for 4.6. Can I get a review of [37262] from @ocean90, @wonderboymusic, or @dd32 ?
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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.