Defer term counts during multiple inserts
|Reported by:||tellyworth||Owned by:|
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.
Change History (6)
- Keywords has-patch added
- Milestone changed from 2.5 to 2.4
- Version set to 2.4