The Nerd Blurb » Tutorials » Scripts » WP E-Commerce Add/Edit Products Media Library Extremely Slow
WP E-Commerce Add/Edit Products Media Library Extremely Slow
Written March 15th, 2012 by WebGuru

I recently had the pleasure of installing WordPress with WPEC on a HostGator account, with images NOT stored in folders by month (all in one folder). I love WordPress, have become a bit of an expert with it, and have used WPEC on two or three sites now, but never on a HostGator server (and not with the Gold Cart or other plugins that I got to play with this time).

One big issue I had was with accessing the Media Library from the Add/Edit Product page (when you click Upload Image and switch to the Media Library). If there was no one accessing it for a while, it would load the Media Library tab pretty quick, but after the first couple of pages it starts taking 15-30 seconds to load a page, sometimes longer, which was unacceptable. I spent several hours with HostGator trying to determine what was different on their servers, since I have similar setups on other hosts, I assumed it had to be an issue with the host.
I still know there has to be some server environment setting that is causing the issue since another server runs this Media Library with no problems. However, after over two weeks of poor support from HostGator, I finally got an answer, which by itself was still wrong, but gave me a clue to what the trigger could be, and after some digging, I found this code, took it out, and now the Media Library page load much faster.

WPEC runs some additional code when you access this Media Library (compared to the Posts/Pages standard Media Library and the Media->Library page). One thing it does is regenerate the size metadata for each image in case it’s missing, each time you load a Media Library page.

File: wpsc-admin/includes/display-items-functions.php, line 978:


		// regenerate size metadata in case it's missing
		if ( ! $check || $current_size['width'] != $settings_width || $current_size['height'] != $settings_height ) {
			if ( ! $metadata = wp_get_attachment_metadata( $post->ID ) )
				$metadata = array();
			if ( empty( $metadata['sizes'] ) )
				$metadata['sizes'] = array();
			$file = get_attached_file( $post->ID );
			$generated = wp_generate_attachment_metadata( $post->ID, $file );
			$metadata['sizes'] = array_merge((array) $metadata['sizes'], (array) $generated['sizes'] );

			wp_update_attachment_metadata( $post->ID, $metadata );
		}

While I understand the need to run this check, maybe it would be better to run this check only once, or move it to a tool with options to check an individual image from the media library or to check all images from the Store settings page.

So for now, I have commented this code out and will take note to test it and remove it again when updating the plugin. I’m sure there are probably other sites with this issue, but I could not find anything about this issue anywhere. Now I have some other questions….

What is different that causes this on HostGator (as a client on our reseller account)? Is there some other problem that is triggering this check to run? Can anyone confirm this issue? What would be the consequences of disabling this code (as I have done)? I’m interested to hear if anyone else has ever seen this or knows anything about this type of issue. Can anyone shed some more light on this issue?

P.S. I have also posted these questions on the GetShopped forums, I will try to keep this post updated with the responses I get there.


One Comment (Leave a Reply)

  1. JayCee (July 23, 2012)

    Hello,

    I had exactly the same issue on a site hosted by OVH, and your solution worked fine, thank you very much for the tip.
    Did you get any feedback from GetShopped forums ?

    Thanks again,

    JC



Leave a Reply

Name
(* required)
Email Address
( * required - will not be published)
Web Site
Comment
(* required)