Opened 11 years ago
Closed 11 years ago
#34368 closed enhancement (fixed)
WP_Site_Icon->get_post_metadata performance improvement
| Reported by: | ap.koponen | Owned by: | obenland |
|---|---|---|---|
| Priority: | normal | Milestone: | 4.4 |
| Component: | Administration | Version: | 4.4 |
| Severity: | normal | Keywords: | has-patch commit has-unit-tests |
| Cc: | Focuses: | performance |
Description
Hi,
while trying to improve the performance of a plugin that used a lot of get_post_meta (WooCommerce Bookings) I noticed from my Cache Grind analysis that WP_Site_Icon->get_post_metadata was calling get_option a lot (11 336 times in my case).
I noticed that this call was unnecessary, if $single and $meta_key did not match so I refactored the function to call get_option only if it was necessary. This refactoring reduced the get_option calls to 0.
Ari-Pekka Koponen
Attachments (3)
Change History (9)
#1
@
11 years ago
- Keywords has-patch commit added
- Milestone Awaiting Review → 4.4
- Owner set to
- Status new → assigned
Nice catch!
#3
in reply to: ↑ 2
;
follow-up:
↓ 4
@
11 years ago
Replying to swissspidy:
34368.diff uses strict comparison
Be careful with strict comparison:
<?php var_dump( get_option( 'site_icon' ) ); // string(4) "1785"
#4
in reply to: ↑ 3
;
follow-up:
↓ 5
@
11 years ago
- Keywords has-unit-tests added
Replying to ocean90:
Replying to swissspidy:
34368.diff uses strict comparison
Be careful with strict comparison:
<?php var_dump( get_option( 'site_icon' ) ); // string(4) "1785"
That wasn't a problem in the unit test (see 34368.2.diff), but I added an (int) nonetheless.
#5
in reply to: ↑ 4
@
11 years ago
Replying to swissspidy:
That wasn't a problem in the unit test (see 34368.2.diff),
Right, because _insert_attachment()/wp_insert_attachment() returns an integer. But if it gets saved through the Customizer then the value is currently a string.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Diff for the refactored code.