Fixed problem of memory exhaustion
-
Hello!
While working here I got to need to use the job-manager. It’s excellent, but when I deployed all the jobs, 2600, the problem started: “Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes)”.
After a look around the plugin code I found the problem: it stores ALL the posts in a variable ($jobman_shortcode_all_jobs) just to use a count method in some places to check the amount of posts available. Instead of storing so much data with no use, I changed it to retrieve just the number of posts using a custom query. So things are working cleaner, faster and using almost no memory compared to what it used to.
To apply this idea I changed the var $jobman_shortcode_all_jobs to $jobman_shortcode_jobs_number in all the files of the plugin, removed all the count functions applied to it in all files and changed this piece of code in “frontend-jobs.php”:
$jobs = get_posts( $args ); $args['posts_per_page'] = ''; $args['offset'] = ''; $args['numberposts'] = -1; $jobman_shortcode_all_jobs = get_posts( $args );
to:
$jobs = get_posts( $args ); $query = "SELECT te.name FROM {$wpdb->prefix}posts po"; $query .= " LEFT JOIN {$wpdb->prefix}term_relationships re ON re.object_id = po.id"; $query .= " LEFT JOIN {$wpdb->prefix}term_taxonomy ta ON re.term_taxonomy_id = ta.term_taxonomy_id"; $query .= " LEFT JOIN {$wpdb->prefix}terms te ON te.term_id = ta.term_id"; $query .= " WHERE ta.taxonomy = 'jobman_category'"; $query .= " AND po.post_type='jobman_job'"; if( 'all' != $cat ) $query .= " AND te.name='".$args['jcat']."'"; $jobman_shortcode_jobs_number = $wpdb->query( $query );
Oh! You have to add the wordpress global var $wpdb to the beginning of the function in the file “frontend-jobs.php” or things will not work. I’ll be like this:
function jobman_display_jobs_list( $cat ) { global $jobman_shortcode_jobs, $jobman_shortcode_jobs_number, $jobman_shortcode_category, $jobman_shortcodes, $jobman_field_shortcodes, $wp_query, $wpdb;
I hope this will be helpful.
??
- The topic ‘Fixed problem of memory exhaustion’ is closed to new replies.