Viewing 2 replies - 1 through 2 (of 2 total)
  • On line 164 of SharePulse.php you can edit where the argument for “posts_per_page”.

    It is currently set to -1 which indicates an unlimited number of posts will be processed. This will likely bug out on most servers if there are many thousands of posts. I would be inclined to set that to something more sane, like 1000. This wouldn’t limit it to a specific time period, but would stop the plugin from processing an excessively large number of posts.

    There is a filter called “sp_get_posts_args” which can be used to control this. I’ll prepare some code to provide control over this and post it here shortly.

    Here’s some code to limit this. This can be placed into a theme or plugin.

    <?php
    
    /*
     * The SharePulse plugin is intended to work with an unlimited number of posts
     * But since it is attempts to process them all at once, this will not work as
     * intended with sites with enormous numbers of posts
     *
     * This function works around this limitation by limiting the number of posts.
     *
     * @param   array   $args    The arguments
     * @return  int     The number of posts to process
     */
    function sharepulse_limit_number_of_posts( $args ) {
    	$args['posts_per_page'] = 1000;
    
    	return $args;
    }
    add_action( 'sp_get_posts_args', 'sharepulse_limit_number_of_posts' );

    It may be sensible to change the default value in the core plugin though, as at least with 1000 posts it will probably work, whereas with an unlimited number of posts it will simply fail on huge sites.

    Iterating through in sections would be even better. That way it could process them in batches of 100 or so to avoid hammering the server too aggressively.

    Many services such as WordPress.com VIP will actually disallow anything which attempts to use a post count of more than 100 due to the risk of excessive server load, so even 1000 is quite high.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Limit to past year’ is closed to new replies.