Make WordPress Core

Opened 7 years ago

Closed 4 years ago

#17920 closed enhancement (fixed)

Unnecessary code in wp.getPage

Reported by: nprasath002 Owned by: SergeyBiryukov
Milestone: 4.1 Priority: normal
Severity: minor Version: 3.2
Component: XML-RPC Keywords: has-patch dev-feedback
Focuses: Cc:


Pages Does not have categories

Attachments (2)

wp.getPage.patch (906 bytes) - added by nprasath002 7 years ago.
17920.diff (650 bytes) - added by markoheijnen 4 years ago.

Download all attachments as: .zip

Change History (11)

#1 follow-up: @F J Kaiser
7 years ago

  • Keywords 2nd-opinion added

But categories can be added to pages.

#2 in reply to: ↑ 1 @DrewAPicture
7 years ago

Replying to F J Kaiser:

But categories can be added to pages.

Agreed. On one of my sites, pages rely on categories to display specific posts from said categories. At the time it was in deference to creating a new custom post type.

#3 @F J Kaiser
7 years ago

  • Keywords close added; 2nd-opinion removed

I close it now as I think there are enough use cases for this left.

#4 follow-up: @nacin
7 years ago

We could wrap this into a post_type_supports check and save the queries.

#5 in reply to: ↑ 4 @F J Kaiser
7 years ago

Replying to nacin:

We could wrap this into a post_type_supports check and save the queries.

Would this add any performance in- or decrease?

#6 @markoheijnen
6 years ago

Now there is wp_getPost. I recommend using that instead of wp_getPage. That said I'm not sure how to use post_type_supports. There isn't one for categories, right?

Weird thing is that we expect only categories and not tags or custom taxonomies. I think we should copy the stuff from _prepare_post to _prepare_page and that will solve the issue with a fallback for categories

#7 @markoheijnen
6 years ago

  • Keywords dev-feedback added; close removed
  • Summary changed from Unnecessary code to Unnecessary code in wp.getPage

Wonder if we can inherit most of the getPost functionality in getPage.

4 years ago

#8 @markoheijnen
4 years ago

  • Milestone changed from Awaiting Review to 4.1
  • Type changed from defect (bug) to enhancement

Created a new patch that adds a is_object_in_taxonomy() check. It will prevent one query like this one:

SELECT t.term_id FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('category') AND tr.object_id IN (2) ORDER BY t.name ASC

Moving to 4.1 for consideration.

#9 @SergeyBiryukov
4 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 29731:

XML-RPC: Check if category support was added for pages before calling wp_get_post_categories() to avoid unnecessary query in wp.getPage.

props markoheijnen, nprasath002.
fixes #17920.

Note: See TracTickets for help on using tickets.