Catalog issues loads of queries -- patch to optimize!

Project:Ubercart Contributions
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:closed
Description
Project: 
Ubercart

Hi!
I was somewhat shocked to see the number of queries that was used to generate the catalog block (and the catalog pages too I suppose). Specifically there were a large number of duplicate queries from taxonomy_get_parents() (due to the fact that that function is not cached). I tracked that down to uc_catalog_term_path() which calls taxonomy_get_parents_all() which in turn calls taxonomy_get_parents() several times.

I thought that the expensive use of uc_catalog_term_path() may not be needed when building the catalog tree (_uc_catalog_navigation), since the parents of each catalog node are already known. Hence it's possible to build the full catalog path without using uc_catalog_term_path(). This required an extra argument to _uc_catalog_navigation(): $current_path.

I tried this on a specific page and went from about 250 to 120 queries! I don't know if all use cases will gain as much as that, but it sure looks good.

Attaching the patch!

PreviewAttachmentSize
uc_catalog-path_optimization.patch_.txt2.35 KB
Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: Catalog issues loads of queries -- patch to optimize!

This patch looks pretty good, and I appreciate it. However, it's only applicable to alpha7b. A similar fix has been put into the repository since then. uc_catalog_term_path() is now far less complicated and expensive.

zoo33@drupal.org's picture
Offline
Joined: 08/23/2007
Juice: 13
Good news
Assigned to:Lyle» zoo33@drupal.org

Well, that's good news! I looked for an issue about this before I started hacking, but I didn't find one. Anyway, problem solved...

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: Good news
Assigned to:zoo33@drupal.org» Lyle

Yeah...I don't always post an issue when I find something to fix. Probably not a good habit to be in, and it's even worse with the server crash getting rid of all the evidence that I had fixed things.

I want to encourage good patches to the code, but I do ask that any effort in that direction be geared towards the bazaar repository. Pretty please.