Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#26744 closed enhancement (fixed)

Twenty Fourteen: reduce the number of queries when there is no featured post

Reported by: chouby's profile Chouby Owned by: lancewillett's profile lancewillett
Milestone: 4.0 Priority: normal
Severity: normal Version: 3.8
Component: Bundled Theme Keywords: has-patch needs-testing
Focuses: Cc:

Description

Thanks to the transient used by Feature_Content::get_featured_post_ids, the featured post ids are not queried at each page load. The transient is however never set if there is no featured post resulting in performance loss.

Attachments (6)

26744.patch (1.4 KB) - added by Chouby 10 years ago.
26744.2.patch (1.2 KB) - added by Chouby 10 years ago.
26744.3.patch (1.3 KB) - added by Chouby 10 years ago.
26744.diff (2.4 KB) - added by obenland 10 years ago.
26744.2.diff (2.4 KB) - added by obenland 10 years ago.
26744.3.diff (2.4 KB) - added by lancewillett 10 years ago.
Use correct variable for featured IDs

Download all attachments as: .zip

Change History (17)

@Chouby
10 years ago

@Chouby
10 years ago

#1 @Chouby
10 years ago

  • Keywords has-patch added

according to my tests, the proposed patch suppresses 6 queries

@Chouby
10 years ago

@obenland
10 years ago

#2 @obenland
10 years ago

  • Keywords needs-testing added
  • Milestone changed from Awaiting Review to 3.9

If we trust our cache busting enough, we could just put those sticky post ids in the transient, if there are no tagged posts. ;)

#3 @lancewillett
10 years ago

  • Milestone changed from 3.9 to Future Release

#4 @lancewillett
10 years ago

  • Keywords needs-refresh added
  • Milestone changed from Future Release to 4.0

@obenland Want to look at this one again?

#5 @ryanshoover
10 years ago

@obenland's patch works great for me.
No featured posts:
26 queries dropped to 24 queries with the patch

1 featured post:
54 queries dropped to 29 queries

Minor gain when there are no featured posts, significant gain with featured posts.

This ticket was mentioned in IRC in #wordpress-themes by obenland. View the logs.


10 years ago

@obenland
10 years ago

#7 follow-up: @lancewillett
10 years ago

  • Keywords needs-refresh removed

Saw a problem in testing: $featured = get_posts( array() ); the variable assignment here should be $featured_ids instead, right?

#8 in reply to: ↑ 7 @obenland
10 years ago

Replying to lancewillett:

the variable assignment here should be $featured_ids instead, right?

Correct, good catch.

#9 @lancewillett
10 years ago

This is my testing results with the updated patch:

With no featured posts:
34 queries on first load, down to 26 queries on second load

With featured posts:
43 queries on first load down to 35 on second load

(Using Debug Bar plugin with define( 'SAVEQUERIES', true ); in my wp-config.php file.)

Last edited 10 years ago by lancewillett (previous) (diff)

@lancewillett
10 years ago

Use correct variable for featured IDs

#10 @lancewillett
10 years ago

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

In 29174:

Twenty Fourteen: optimize featured content lookup to reduce the number of queries for featured posts. Props Chouby and obenland, closes #26744.

#11 @afercia
10 years ago

hi Lance, all,
did you consider to use WP_Query in combination with update_post_thumbnail_cache() instead of get_posts? I wonder why update_post_thumbnail_cache() is a bit obscure and not documented in the Codex, is it still recommended? Read about it in #19949 and looks like a great way to reduce queries when there are many thumbnails to get at once. With 6 featured posts and 6 thumbnails could save 10 queries.
However, it would require to change something also in Jetpack.

Note: See TracTickets for help on using tickets.