Skip to content

Instantly share code, notes, and snippets.

@tamara-m
Forked from trey8611/import-optimizations.md
Created July 30, 2021 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamara-m/1d0f7af6a751a9eef4b594224cf6909f to your computer and use it in GitHub Desktop.
Save tamara-m/1d0f7af6a751a9eef4b594224cf6909f to your computer and use it in GitHub Desktop.
WP All Import - Optimize your import speed.

WP All Import Optimizations

If you have a slow import, or if you're running into a lot of server timeouts, then you can follow these steps to optimize your import.

Slow Import Guide

Follow all of the steps listed here: http://www.wpallimport.com/documentation/troubleshooting/slow-imports/.

Skip posts if their data has not changed

You can enable Skip posts if their data in your file has not changed in the import settings of your existing imports: https://d.pr/i/x4tndp. When enabled, posts will be skipped if their data hasn't changed since the last time you ran the import. If the data hasn't changed, imports that used to take hours will complete in minutes.

Note: This setting is enabled by default in new imports created with WP All Import v4.6.2 and above.

Run the import via WP-CLI

As long as you're not importing a huge amount of data, you can use WP-CLI to import your data much faster: https://www.wpallimport.com/documentation/developers/wp-cli/. Please keep in mind that larger imports may not work via WP-CLI due to server timeout limits. And, you'll need to make sure your WP All Import Add-Ons are compatible with WP-CLI.

Settings that decrease speed

It's possible that you can't change these settings, but if you're able to it will help with speed:


  • Scan through post content and import images wrapped in <img> tags -> Disable this to increase speed (All Import -> Edit Import -> Images).
  • Search through the Media Library for existing images before importing new images & Keep images currently in Media Library -> Enable these to increase speed in subsequent runs of the import (All Import -> Edit Import -> Images).
  • Don't check for duplicate SKUs -> Enable this to increase speed (All Import -> Edit Import -> WooCommerce Add-On -> Add-On Options).
  • Use StreamReader instead of XMLReader to parse import file -> Disable this to increase speed (All Import -> Import Settings -> Configure Advanced Settings). Make sure to test your feed/file in a new import to confirm that it still works right with this disabled.

Speeding up "Existing Items" Imports

When using Manual Record Matching (see documentation) the fastest and most versatile option is "Post ID". If you don't have the Post ID in your file, you can use a custom PHP function to find the ID: see documentation.

As an example, if you're updating WooCommerce products and you're using these settings: https://d.pr/i/XzCxWm, you can switch to Post ID and use this function to greatly increase the speed of the import:

(NOTE: The latest version of WP All Import Pro and the WooCommerce Add-On do this automatically, but I'm keeping this here as an example)

[wc_get_product_id_by_sku({sku[1]})]

See: https://d.pr/i/tDncIB.

Actions from other plugins

In an attempt to stop other plugins from running a bunch of actions during post save/updates, try enabling Increase speed by disabling do_action calls in wp_insert_post during import (All Import -> Manage Imports -> Import Settings -> Configure Advanced Settings): https://d.pr/c8LRQ. Make sure to check your imported posts and confirm that they're correct with this setting enabled.

In some cases, this change can significantly improve the import speed.

Database Clean Up

Before you clean up your database, it's extremely important to make a back up that you can roll back to. After you've made a back up, you can use one of the following plugins to clear transients and orphaned data:

Disable Image Optimization Plugins

If you're using a plugin like EWWW Image Optimizer, or Smush Pro, you should disable them before you start your import. These types of plugins can cause the imports to run extremely slowly.

Full Conflict Test

If other plugins (or your theme) are running a lot of do_action calls during the import, it could cause things to crawl. Check this by running a full conflict test: http://www.wpallimport.com/documentation/troubleshooting/plugin-theme-conflicts/.

Slow Queries

Here's a detailed guide on troubleshooting a slow WordPress install in general: https://carlalexander.ca/troubleshoot-wordpress-performance/.

Resource Usage

If the import is causing your server to max out its resources (CPU/Memory), the import will run extremely slowly. Sometimes the only way to fix this is to upgrade your server, but it's possible that changing some settings in WP All Import could help.

These are the things that increase CPU/Memory usage:

  • Low number of records per iteration (see: https://d.pr/i/Vakkd3).
  • Huge amount of images.
  • Huge amount of taxonomy terms per record (categories/tags/product attributes/etc).
  • Huge amount of variations per product (in a WooCommerce import).

To remedy some of these issues, you can:

Increase speed after optimizations

Once you've done everything listed above, you can try increasing the records per iteration via the Import Settings to speed things up: https://d.pr/i/Vakkd3. The higher you can set this, the faster the import will run.

Troubleshooting terminations / failures

If you set the records per iteration higher and the server terminates the import, you can work with your web host to find the error in the logs on your server to see what's causing the termination and fix it: https://gist.github.com/mbissett/d98d1acdf4b2ba11bc67d6f652d4497c.

If they can't find anything in the logs, try using the error-revealer plugin to log the error yourself: https://github.com/mbissett/error-revealer. Make sure to follow the directions closely and revert the changes to your wp-config.php file when you're done.

Some common problem areas are:

  • (Server) CPU Usage
  • (Server) Memory Usage
  • (PHP) max_execution_time
  • (PHP/Apache) FcgidIOTimeout
  • (PHP/Apache) FcgidBusyTimeout
  • (PHP) mysql.connect_timeout
  • (PHP) default_socket_timeout
  • (MySQL) wait_timeout
  • (MySQL) interactive_timeout

Web Host

The web host and server you choose will have a direct impact on the speed of your imports. If you're trying to import a lot of data on a bad server, it's going to be slow no matter what you do. If you follow all of the steps above and nothing increases the speed, try switching to a good web host like one of the following:

  • Kinsta
  • LiquidWeb
  • Nexcess

Advanced

WARNING: Follow these instructions closely or you will end up with many duplicate posts.

On the very first run of your import, if you're sure that there are no duplicate posts in your import file, you can use this method to import your posts very quickly:

  1. Add the following code in the Function Editor at All Import -> Settings:
add_filter( 'wp_all_import_is_check_duplicates', 'wpai_is_check_duplicates', 10, 2 );
function wpai_is_check_duplicates( $is_check_duplicates, $import_id ) {
	return false;
}
  1. Create and/or run your import.
  2. Very important: remove the above code from the Function Editor. If you do not remove the code then every import will create duplicate posts every time you run them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment