Make WordPress Core

Opened 16 years ago

Closed 13 years ago

#2621 closed defect (bug) (fixed)

get_nested_categories() and friends use a lot of DB queries

Reported by: mdawaffe's profile mdawaffe Owned by: mdawaffe's profile mdawaffe
Milestone: 2.6 Priority: normal
Severity: normal Version: 2.1
Component: Administration Keywords: db queries cache
Focuses: Cc:


get_nested_categories(), cat_rows(), and wp_dropdown_cats() spend at least one query per category. The attached patch uses the built in caching to eliminate all but one or two queries. I do not know if this proposed method is actually any faster.

Note: these are admin-side only functions, so DB hits aren't as important.

Attachments (2)

2621.diff (8.7 KB) - added by mdawaffe 16 years ago.
Reduce DB hits by orders of magnitude for admin side category template functions.
wp_category_checklist.diff (2.5 KB) - added by ryan 14 years ago.

Download all attachments as: .zip

Change History (14)

16 years ago

Reduce DB hits by orders of magnitude for admin side category template functions.

#1 @ryan
16 years ago

Can get_categories() be used in here?

#2 @mdawaffe
16 years ago

The advantage of get_all_category_ids is that, with the current cache implementation, it does the following query the first time it's run and caches the result in a PHP variable (and on the file system if it can).

SELECT * FROM wp_categories

get_categories(), though much more robust, does no caching. Without adding caching to gote_categories(), even if we're careful within one function, we'll still run a SELECT for each function dealing with the categories table. For example, categories.php run both cat_rows() and wp_dropdown_cats().

#3 @ryan
15 years ago

Stale patch. Needs update.

#4 @markjaquith
15 years ago


Can you freshen this up for 2.1, or should we push it off to 2.2 (remember, 4 months from 2.1 to 2.2)?

#5 @mdawaffe
15 years ago

  • Milestone changed from 2.1 to 2.2

Push it. The category get functions got an overhaul which fixed most of this up.

I can revisit it later, but it's not worth looking at now to save one or two queries in the admin.

#6 @foolswisdom
15 years ago

  • Milestone changed from 2.2 to 2.3

#7 @Nazgul
15 years ago

  • Keywords bg|has-patch bg|needs-testing removed
  • Milestone changed from 2.3 (trunk) to 2.4 (future)

#8 @pishmishy
14 years ago

  • Milestone changed from 2.5 to 2.6

Bumping milestone for feature freeze. Bordlerline as to whether this is a feature or simply an enhancement that could be included as a fix. Patch is stale though so I'll bump.

14 years ago


#9 @ryan
14 years ago

(In [7737]) wp_category_checklist() and wp_link_category_checklist() to replace the nested cats code. see #2621

#10 @ryan
14 years ago

(In [7739]) Don't query post cats if no post. see #2621

#12 @ryan
13 years ago

  • Milestone changed from 2.9 to 2.6
  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.