If this is your first visit, check our documentation. To post, register or login.
Forums / Features Wish List / Inefficient way to display multiple images in additional_images.php

Inefficient way to display multiple images in additional_images.php

Started by ettendu on 23 Jun 2012, 11:47 PM · Views: 120

Results 1 to 2 of 2
23 Jun 2012, 11:47 PM
#1
ettendu avatar

ettendu

New Zenner

Join Date:
Mar 2006
Posts:
22
Plugin Contributions:
0

Inefficient way to display multiple images in additional_images.php

Technically , this is not a bug, but rather a very inefficient way to find additional images for an image.
This problem has been around since 1.3.x , and I checked that it is still in 1.5.x

In includes/modules/additional_images.php

From Line 43,
you are going through the entire directory to find matching image files that has a form of
$products_image_base[num].$products_image_extension

But if there are thousands of file in the directory, that will really become extremely inefficient.
I suggest maybe its better to assume that we won't skip the additional image number and only search
the additional in a sequential way up till we don't find the next number.

e.g.
image base is = "test_"
we will search the directory from test_1 and stop when test_n doesnt exist.

as a sample, here is some sample code

$done = false;
$count=1;
while (!$done) {
$filename = $products_image_directory . $products_image_base . $count . $products_image_extension;
//echo "$f = " . $filename . "\n";
if (file_exists($filename)) {
  $images_array[] = $products_image_base.$count.$products_image_extension;
  $count++;
}
else
  $done = true;
}
25 Jun 2012, 5:24 AM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Re: Inefficient way to display multiple images in additional_images.php

Thanks for your thoughts. However, this is not a bug report. Moving it to the Features Wishlist section instead.

Your suggested different approach doesn't take into consideration the fact that some stores might want to name their images in some format other than numbering them sequentially. Yours requires that they use sequentially-numbered suffixes, with no breaks in numbering, and no zero-padding for easy management/sorting.

Much more efficient is the built-in approach where the storeowner uses subfolders to split off groups of images. No code changes required for that. And allows for much more flexibility in what suffix is used instead of requiring sequential integers.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.