get_post_meta() on post with large amount of meta keys uses too much memory
|Reported by:||joehoyle||Owned by:|
I think it's likely there has been a ticket on this in the past, but I couldn't find one so here goes!
If I have a post that have say 25k post meta entries, and I call get_post_meta( $id, 'foo', true ) then update_meta_cache is going to cause all post metas to be loaded into memory.
In most cases I can see this makes sense, however I recently had an issue where I was storing contest votes as meta keys, a post had 30k votes, and would take about 70MB of memory to get any meta key of that post (even if I didn't want votes). This is fairly edgecase, but the idea that all meta for a post is always loaded even if you don't want it is perhaps over presumptuous as a dev may be storing a large amount of data in meta.
With persistant object caching this is somewhat worse, as the object cache store gets very large.
I am not proposing this functionality is removed, maybe just a filter or something in http://core.trac.wordpress.org/browser/trunk/wp-includes/meta.php#L524 so one could either adjust the query or perhaps pass an array of meta keys to exclude from the sql query