Ticket #2621 (new defect)

Opened 3 years ago

Last modified 7 months ago

get_nested_categories() and friends use a lot of DB queries

Reported by: mdawaffe Assigned to: mdawaffe
Priority: normal Milestone: 2.9
Component: Administration Version: 2.1
Severity: normal Keywords: db queries cache
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

2621.diff (8.7 kB) - added by mdawaffe on 04/01/06 10:47:55.
Reduce DB hits by orders of magnitude for admin side category template functions.
wp_category_checklist.diff (2.5 kB) - added by ryan on 04/18/08 17:00:17.
wp_category_checklist()

Change History

04/01/06 10:47:55 changed by mdawaffe

  • attachment 2621.diff added.

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

04/01/06 23:10:40 changed by ryan

Can get_categories() be used in here?

04/02/06 01:18:20 changed by mdawaffe

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().

12/01/06 04:23:26 changed by ryan

Stale patch. Needs update.

12/04/06 14:47:58 changed by markjaquith

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

01/09/07 08:30:36 changed by mdawaffe

  • 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.

04/12/07 18:30:07 changed by foolswisdom

  • milestone changed from 2.2 to 2.3.

06/12/07 22:15:39 changed by Nazgul

  • keywords changed from db queries cache bg|has-patch bg|needs-testing to db queries cache.
  • milestone changed from 2.3 (trunk) to 2.4 (future).

02/12/08 09:34:37 changed by pishmishy

  • 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.

04/18/08 17:00:17 changed by ryan

  • attachment wp_category_checklist.diff added.

wp_category_checklist()

04/18/08 17:41:10 changed by ryan

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

04/18/08 18:12:05 changed by ryan

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