get_new_entries function is not performance friendly
-
Context
Job_Postings_Helper::get_new_entries();
is called onis_admin()
, this to show new entries bubble.Issue
When site is big or have big “new” entries, the query become super slow, and causing memory to be exhausted. And what makes matter worst is, because front end also using admin-ajax, so that’s alsois_admin()
and this query slow it down.Proposed Solution
Specify only fields that needed$args = array( 'post_type' => 'job-entry', 'meta_key' => 'job_entry_viewed', 'meta_query' => array( array( 'key' => 'job_entry_viewed', 'value' => 'no', 'compare' => '==', ), ), 'posts_per_page' => -1, 'fields' => 'ids', // id only, so it doesn't initiate full Post object to all of it ); $new = new WP_Query( $args ); $new = $new->found_posts; wp_reset_postdata(); wp_reset_query();
And cache should be implemented here as well, and break the cache only if the counter possibly changed:
- ajax_submit
- render_job_entry_metabox
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘get_new_entries function is not performance friendly’ is closed to new replies.