Site icon Hip-Hop Website Design and Development

get_post_meta slowing down my web page load (in a plugin)

I have been engaged on this venture the place I must load occasions (customized submit sort) and an entire bunch of meta information for each occasion. The issue is that web page loading occasions are getting longer and longer when increasingly more occasions get added.

In the beginning with only some occasions this wasn’t an issue in any respect, however now when there are 100+ occasions within the system web page hundreds take as much as 6 seconds which is just too lengthy.

Instance of what I am doing: Present all of the occasions within the system
(All beneath is finished inside a plugin)
I load all occasions with get_posts and specify the customized submit sort.
I loop by all of the posts and get all of the meta information with get_post_meta in a single name.

When testing the place the bottleneck was, I discovered that once I take away get_post_meta execution time went down from 4.5 seconds to 14ms.
I additionally examined what would occur if I load each meta information individually like so: get_post_meta($post->ID, "meta_value", true);

If I’ve a view the place I solely want a couple of meta values this quickens the method to the place I might lower 20% of the loading time, however once I want virtually all, there was no change in loading occasions.

I additionally seen that utilizing get_post_custom would not actually assist on this case.

After wanting round on-line (right here, blogs, and many others..), individuals identified that if you do a get_posts, all meta information is routinely retrieved and cached. Nevertheless it appears this is not true once I have a look at the execution time and quantity of queries which might be processed.

Is there any method of dashing this up additional through php/mysql?

One factor I used to be pondering of was: is there a method of getting all posts and meta information for every submit in a single name. However I did not have any luck of discovering one thing on-line that will assist me reaching this.