paulirish/infinite-scroll — pull request #373 by beebs93 (2013-04-10 22:24:24+00:00)
Title: 'get_media_item_args' filter callback chokes Media modal loading time

On large sites with thousands of images, the query run [here](https://github.com/paulirish/infinite-scroll/blob/master/wordpress-plugin/includes/admin.php#L92) can dramatically slow down the time it takes for the Media modal to load all of the available images.

The query mentioned above was taking 0.5 to 1.5 seconds to run for each image given that the table columns referenced (post_type, post_mime_type, post_parent and post_title) do not have a multi-column index by default in wp_posts. When query caching is not available it causes severe loading times for the images.

We're assuming the ['send_to_editor' method](https://github.com/paulirish/infinite-scroll/blob/master/wordpress-plugin/includes/admin.php#L74) was meant for the Infinite Scrolling settings page, but it's actually running every time the Media modal is opened - anywhere on the site. Thus, [the logic check](https://github.com/paulirish/infinite-scroll/blob/master/wordpress-plugin/includes/admin.php#L80) is always failing and running the query instead.

Our proposed solution was to only allow the chance of that query running whenever an image has been uploaded. You could add an additional check to see if the user is currently on the Infinite Scrolling settings page, but this worked well enough for us.

Thanks!

------

Majority of credit goes to [Eric Shelkie](https://github.com/shelkie) for meticulously testing the plugin for the exact line of code causing this issue.