WordPress.org

Make WordPress Core

Opened 8 years ago

Closed 5 years ago

#2621 closed defect (bug) (fixed)

get_nested_categories() and friends use a lot of DB queries

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

Description

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 8 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 6 years ago.
wp_category_checklist()

Download all attachments as: .zip

Change History (14)

mdawaffe8 years ago

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

comment:1 ryan8 years ago

Can get_categories() be used in here?

comment:2 mdawaffe8 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().

comment:3 ryan7 years ago

Stale patch. Needs update.

comment:4 markjaquith7 years ago

mdawaffe,

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)?

comment:5 mdawaffe7 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.

comment:6 foolswisdom7 years ago

  • Milestone changed from 2.2 to 2.3

comment:7 Nazgul7 years ago

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

comment:8 pishmishy6 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.

ryan6 years ago

wp_category_checklist()

comment:9 ryan6 years ago

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

comment:10 ryan6 years ago

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

comment:12 ryan5 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.