Post by KanKan2022 » Tue Aug 09, 2022 6:06 pm

I've got a lot of image files that I want to rename, but don't want to go through all the time involved with the image cache regeneration. So I modded an extension I have (at the moment it renames the image files in image/catalog/products/image_folders/*.jpg and it updates the database by also changing the name for the main image and additional images). The existing extension works great, but then on each product page it has to regenerate all the cache files with the new names. So what I have done is modded the extension so that it also changes all the image cache file names (replaces the substring of the old name to the new name, so all of the different image cache files are exactly the same but with the old substring image name swapped with the new image name - they retain the other info exactly the same, for example image1-40x40.jpg etc). This also works great, but when I go to a product page, it still takes a long time as though it is regenerating, but when I check the cache image files, nothing new has been added/changed - all the files that were renamed remain exactly the same Does anyone know why the product page loads fast when the image has been cached through opencart, but slow when all the filenames and database entries have been renamed instead?
Last edited by KanKan2022 on Thu Aug 11, 2022 10:38 am, edited 1 time in total.

New member

Posts

Joined
Sat Jul 02, 2022 4:36 pm

Post by thekrotek » Tue Aug 09, 2022 7:32 pm

You really, really don't have to modify image cache manually. You have a resize() function which you should use instead in your code.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by ADD Creative » Tue Aug 09, 2022 7:41 pm

What are the modified dates of the files? OpenCart uses filemtime() to get the modified date to compare to see if the cache file need regenerating. Do you have any other form of caching?

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by KanKan2022 » Tue Aug 09, 2022 7:58 pm

Thanks for your reply. With the resize function, do you mean when it converts the image files into its cache files at different dimensions? I can rename all my cache images in a couple of minutes, but to convert all the image files to their cache counterpart would take a very long time, hence I'm wondering why renaming them doesn't seem to work?

New member

Posts

Joined
Sat Jul 02, 2022 4:36 pm

Post by KanKan2022 » Tue Aug 09, 2022 8:02 pm

Hello ADD Creative. The renamed cache files have exactly the same time stamp.

New member

Posts

Joined
Sat Jul 02, 2022 4:36 pm

Post by thekrotek » Tue Aug 09, 2022 11:00 pm

KanKan2022 wrote:
Tue Aug 09, 2022 7:58 pm
Thanks for your reply. With the resize function, do you mean when it converts the image files into its cache files at different dimensions? I can rename all my cache images in a couple of minutes, but to convert all the image files to their cache counterpart would take a very long time, hence I'm wondering why renaming them doesn't seem to work?
I don't really understand why you want to rename cached image files.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by KanKan2022 » Wed Aug 10, 2022 6:20 am

I have thousands of images that were taken by my camera and are in the format IMG_1234.jpg. I want to rename them to SEO friendly image names, such as product_A-1.jpg, product_A-2.jpg etc. So for this example to change IMG_1234 to product_A, instead of renaming the file and assigning it as an image for the product_A in admin- product/edit and opening up that product on the front end so that all the cache image files can be created - all of which takes great time, especially with thousands and thousands of images and which causes a very slow website because need to regenerate all of the cache files, I have done the following through a php script:
Rename in image/catalog/product_A-folder/IMG_1234.jpg to image/catalog/product_A-folder/product_A.jpg (and rename every image that is assigned to every product, sequentially: -2.jpg, -3.jpg etc.
Update corresponding database entries: product SET image, product_image SET image
And in image/cache/catalog/product_A/IMG_1234-100x100.jpg, IMG_1234-40x40.jpg, etc rename substring IMG_1234 to product_A so it becomes image/cache/catalog/product_A/product_A-100x100.jpg, product_A-40x40.jpg etc. and do this for every image of every product.
All of this works, so my question is why is my front end so slow after doing this - it is slow as though it is regenerating the cache files, but it isn't. The renamed cache files remain unchanged. Is there another part of opencart that I have missed that needs to be changed also?

thekrotek - If I just rename the image files and database entries, the front end becomes super slow because it needs to regenerate all the cache image files again on a page visit- it is much much quicker for me to just rename those files if opencart can accept that and not slow down the front end on a first page visit again, that is why I am looking at it this way thanks.

New member

Posts

Joined
Sat Jul 02, 2022 4:36 pm

Post by thekrotek » Wed Aug 10, 2022 2:46 pm

The frontend will become slow for a short period of time, so it's not really worth the effort.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by paulfeakins » Wed Aug 10, 2022 5:04 pm

KanKan2022 wrote:
Wed Aug 10, 2022 6:20 am
All of this works, so my question is why is my front end so slow
Because it doesn't work. And as others have said this is NOT the correct way to do this.

Rename your source files and let OpenCart take care of the cache files.

Don't mess about with scripts and changing the database.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by KanKan2022 » Wed Aug 10, 2022 6:49 pm

Learn to read Paul. What I have scripted does work exactly as I intended. Your answers for nearly all your posts including this have no value whatsoever. Gee, another thousand useless answers and I might get to guru status also. What I have asked - which again you had no answer for (maybe if Straightlight answered then you could have quoted him and agreed - well done , another pat on the back for Paul), is why renaming does not work. I didn't ask you why it shouldn't be done. You stated for me to rename the source files and let opencart do the rest, what is the "rest" that you speak of?? Maybe give an answer as to why renaming everything exactly as opencart would name them doesn't work. That would be more constructive then my criticism of you. Oh, and by the way I didn't like the tone of your reply, careful or a ban might be coming your way.

New member

Posts

Joined
Sat Jul 02, 2022 4:36 pm

Post by JNeuhoff » Wed Aug 10, 2022 9:23 pm

@KanKan2022 : Just a thought: Have you checked that your renamed cache image files have the same access rights, as well as the same owner/group ? Also, what's your website URL? Maybe you are using one of the many 3rd party poor quality web themes, such as Journal3, which can slow down your website?

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by KanKan2022 » Thu Aug 11, 2022 7:23 am

BTW I am doing this on a test site. I don't know how the timestamp works with opencart knowing that the cache files weren't regenerated by itself, but I can see what is happening. Opencart IS regenerating most of the cache files again and I don't know why (I copied the cache folder before opening up a product on the front end for comparison). I compared the regenerated files with the renamed files, they have exactly the same name, exactly the same size and exactly the same permissions. The renamed files have the original timestamp as the original files it renamed, and naturally the newly created cache files have the current date time stamp.
@JNeuhoff Could you please tell me how to check the owner/group - thanks

New member

Posts

Joined
Sat Jul 02, 2022 4:36 pm

Post by by mona » Thu Aug 11, 2022 8:17 am

As stated, OC only creates cache images for those where the cache image does not exist or where the timestamp of the original is newer than the timestamp of the cached image.

Your browser, however, will disregard the possible browser cached old images and does have to load the new images as the url has been changed.
So if you have many images on a page and do not lazy load them and even use http/1.1, then that tends to slow things down on first page load.
This of course disregarding any possible extensions you may have that act on images.

if the slowdown is severe, I still expect that the system believes the original is newer or the cached image does not exist.
You can check this by putting in catalog/model/tool/image.php

Code: Select all

if (!is_file(DIR_IMAGE . $image_new)) {
	$this->log->write('Image cache does not exist, creating: '.DIR_IMAGE . $image_new);
} elseif (filemtime(DIR_IMAGE . $image_old) > filemtime(DIR_IMAGE . $image_new)) {
	$this->log->write('Image original newer, recreating: '.DIR_IMAGE . $image_new);
}
before

Code: Select all

if (!is_file(DIR_IMAGE . $image_new) || (filemtime(DIR_IMAGE . $image_old) > filemtime(DIR_IMAGE . $image_new))) {
and check your oc error log for entries.

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by KanKan2022 » Thu Aug 11, 2022 10:38 am

Thanks, yes it was caused by a timestamp difference issue between the original and cached image files. I'll be able to fix that with the script, thanks mona and all for your much appreciated help :)

New member

Posts

Joined
Sat Jul 02, 2022 4:36 pm
Who is online

Users browsing this forum: ravikumar22 and 79 guests