I’m working on a web application service which is going to use a lot of the built-in Wordpress functionalities but also relies heavily on some customized code and tables to create - among others - relationships between different Custom Post Types.
I’ll need to do some different SQL queries which query several tables and JOINS them in order to get the relationships that I need. These queries are relatively expensive so I would like to do them as little as possible.
How would one go about to, for example, when a user logs into the system, run these relatively expensive queries and set (or attach/append) the result to the specific, current user.
One way I have thought about is to “append” new data to this global $current_user variable, data which has been retrieved via SQL queries when the user logged in.
Another approach could be to store the data within some User Session. The benefits of this method as I see is that the data would be available “out-of-the-box” everywhere, as long as the session exists.
A third option could be to create a new global variable within my functions.php which contains the data and information I would need across the site.
And as a side note, I’ve also thought about “poormans caching” the results, so when the user is first created it stores all of these informations in e.g. the user meta data. I could also create a Custom Post Type called something like “configuration” which would contain all configuration for 1 instance / container which is going to be accessed with custom fields. Both solution will of cause still rely on quering the database because that is what Wordpress does when we access meta-data but it would be far less expensive giving that the data already is “sitting” there. This would also mean that some data would be repeated and then make it redundant, but that is not necessarily a bad thing.
I’m hoping for a discussion, some expertise and experiencing about how to go about this and maybe to learn more on this topic, especially within Wordpress because this will be my first time trying to build a more complex Web application on the Wordpress platform.