Hi,

This is how the beginning of th image_gallery_page function looks like:

function image_gallery_page($type = NULL, $tid = 0) {
  $galleries = taxonomy_get_tree(_image_gallery_get_vid(), $tid, -1, 1);
  for ($i=0; $i < count($galleries); $i++) {
    $galleries[$i]->count = taxonomy_term_count_nodes($galleries[$i]->tid, 'image');
    $tree = taxonomy_get_tree(_image_gallery_get_vid(), $galleries[$i]->tid, -1);

As you can see _image_gallery_get_vid() is called before the for loop and also inside the loop. I believe it would be better to store _image_gallery_get_vid() result in a local variable and reuse it later inside the loop.

A fix could be like this:

function image_gallery_page($type = NULL, $tid = 0) {
  $vid = _image_gallery_get_vid();
  $galleries = taxonomy_get_tree($vid, $tid, -1, 1);
  for ($i=0; $i < count($galleries); $i++) {
    $galleries[$i]->count = taxonomy_term_count_nodes($galleries[$i]->tid, 'image');
    $tree = taxonomy_get_tree($vid, $galleries[$i]->tid, -1);

Regards,
Bartek

CommentFileSizeAuthor
#1 image-HEAD.image-gallery-performance.patch1.29 KBsun

Comments

sun’s picture

Title: Performance tip » Performance: Store result of _image_gallery_get_vid()
Version: 5.x-2.x-dev » 6.x-1.x-dev
Status: Active » Fixed
StatusFileSize
new1.29 KB

Committed attached patch. Next time, please provide a patch, please.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.