Make WordPress Core

Opened 17 years ago

Closed 16 years ago

Last modified 15 years ago

#5377 closed enhancement (fixed)

Defer term counts during multiple inserts

Reported by: tellyworth's profile tellyworth Owned by:
Milestone: 2.5 Priority: normal
Severity: normal Version: 2.5
Component: General Keywords: has-patch
Focuses: Cc:


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:


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)

defer-taxonomy-counts-r6340.patch (1.8 KB) - added by tellyworth 17 years ago.
import-deferred-counts-r6340.patch (613 bytes) - added by tellyworth 17 years ago.

Download all attachments as: .zip

Change History (6)

#1 @tellyworth
17 years ago

  • Type changed from defect to enhancement

#2 @tellyworth
17 years ago

The second patch defers counting when importing a wxr file.

#3 @lloydbudd
17 years ago

  • Keywords has-patch added
  • Milestone changed from 2.5 to 2.4
  • Version set to 2.4

#4 @ryan
16 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [6376]) Defer term counting during import. Props tellyworth. fixes #5377

Note: See TracTickets for help on using tickets.