Opened 9 years ago
Closed 9 years ago
#34368 closed enhancement (fixed)
WP_Site_Icon->get_post_metadata performance improvement
Reported by: | ap.koponen | Owned by: | obenland |
---|---|---|---|
Milestone: | 4.4 | Priority: | normal |
Severity: | normal | Version: | 4.4 |
Component: | Administration | Keywords: | has-patch commit has-unit-tests |
Focuses: | performance | Cc: |
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
@
9 years ago
- Keywords has-patch commit added
- Milestone changed from Awaiting Review to 4.4
- Owner set to obenland
- Status changed from new to assigned
Nice catch!
#3
in reply to:
↑ 2
;
follow-up:
↓ 4
@
9 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
@
9 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
@
9 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.
Diff for the refactored code.