#5377 closed enhancement (fixed)
Defer term counts during multiple inserts
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | 2.5 | Priority: | normal |
Severity: | normal | Version: | 2.5 |
Component: | General | Keywords: | has-patch |
Focuses: | Cc: |
Description
wp_update_term_count() gets called any time a post is inserted with tags or categories. It can cause several queries and cache invalidations per post insert, which adds up quickly during an import.
The enclosed patch provides a wp_defer_term_counting() function that can be used to temporarily disable term counts when inserting multiple posts:
wp_defer_term_counting(true); do_many_inserts(); wp_defer_term_counting(false);
Any deferred counts will be automatically updated when wp_defer_term_counting(false) is called. My testing shows this saves about 6500 queries on a 500 post import.
The patch doesn't touch the import code yet, I wanted to post it for separate review first because it's probably useful elsewhere.
Attachments (2)
Change History (6)
Note: See
TracTickets for help on using
tickets.
The second patch defers counting when importing a wxr file.