Ticket #5377 (closed enhancement: fixed)

Opened 1 year ago

Last modified 1 year ago

Defer term counts during multiple inserts

Reported by: tellyworth Assigned to: anonymous
Priority: normal Milestone: 2.5
Component: General Version: 2.5
Severity: normal Keywords: has-patch
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

defer-taxonomy-counts-r6340.patch (1.8 kB) - added by tellyworth on 11/21/07 11:23:23.
import-deferred-counts-r6340.patch (0.6 kB) - added by tellyworth on 11/21/07 11:29:51.

Change History

11/21/07 11:23:23 changed by tellyworth

  • attachment defer-taxonomy-counts-r6340.patch added.

11/21/07 11:24:12 changed by tellyworth

  • type changed from defect to enhancement.

11/21/07 11:29:51 changed by tellyworth

  • attachment import-deferred-counts-r6340.patch added.

11/21/07 11:30:44 changed by tellyworth

The second patch defers counting when importing a wxr file.

11/21/07 16:59:29 changed by lloydbudd

  • keywords set to has-patch.
  • version set to 2.4.
  • milestone changed from 2.5 to 2.4.

12/12/07 05:14:00 changed by ryan

  • status changed from new to closed.
  • resolution set to fixed.

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