I’m trying to come up with a strategic way to collect large amounts of usermeta data (and output to the screen) while keeping database queries low. Some pages, like the home page, single pages, and category pages, load up in less than half a second with 40-60 queries. Other pages that contain large amounts of usermeta load up in 5-6 seconds with 200-220 queries.
Is there a “best practice” way to do somehow pull all userdata before the website loads (or the first time a website loads) and then tap into that information (IE, a multidimensional array based on user ID) for all other user-based queries on the site? Would the information save on visit (cached on browser), or would it be necessary to use the transient api?
Any thoughts?
You made a lot of statements here, so let’s go through them bit by bit.
The amount of queries isn’t directly an issue, time that they take is. Single really slow query can take more time than hundreds of very fast ones.
Since WP is PHP application every load includes full cycle and is not persistent. There is no “first time” because it starts from nothing every load. The only persistent parts are those that are saved into database or otherwise.
Browser caching, while important, does little to help you improve performance of site itself. Transients are precisely kind of persistent storage appropriate for such use cases.
However, as usual with performance tasks, it is hard to recommend anything without profiling the slow operation. It is exceedingly easy to make faulty assumptions about reasons of slow performance and waste time trying to address them.