#5377 closed enhancement (fixed)
Defer term counts during multiple inserts
| Reported by: | tellyworth | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 2.5 |
| Component: | General | Version: | 2.5 |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: |
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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
The second patch defers counting when importing a wxr file.