Balancing query hooks and caching
A while ago I started introducing some hooks to directly add new fields (and joins) to queries.
Now, I realized this may be nice from a "number of queries" stand point, but it may be detrimental if we want to push more the caching.
Why, you say?
Simply because if you inject a JOIN in a query, that for example should be executed, only for guests or for a particular members group, you are increasing the number of "cases" to be cached separately, leading to more resources used to run queries.
Instead, if the query is "stable" for the core, the caching strategy can be identified without guessing and hoping.
So I was wondering, what do you think?
Better "force" more simple queries that can either be cached separately or just not cached because likely not very relevant for the general impact, or let addon developers build (potentially) "bigger" queries that may be less easy to cache and have other (unforeseen, like conflicts between addons) issues?
Re: Balancing query hooks and caching
Reply #2 –
I know many won't like this, but just use another query for that one. I know it's off topic too.
Most query edits should be an additional query. Any query you change has a huge possibility of breaking.
For your mod, I would create a new table and have the PK be the user ID. You could cache it if you want but you could just add an index to cover that column and it would go straight to memory anyway. Incredibly fast.
Re: Balancing query hooks and caching
Reply #5 –
Frenzied, I was off topic. You're good
Re: Balancing query hooks and caching
Reply #6 –
Frenzie those mods would work in even more places if there were no query or table edits and they just added another table.
Re: Balancing query hooks and caching
Reply #8 –
The only additional thing to worry about is on delete. You gain a lot in the portability of the code and the maintaining of your database though
Re: Balancing query hooks and caching
Reply #10 –
I'm on the phone, so I can't be very detailed, but let's imagine post moderation to work with hooks (and the idea would be to extract that as well as we did with many other features).
If the page load before the cache is done by a moderator it would include unapproved posts, that would be then presented to non-moderators until the cache expires.
If the page load before the cache is done by a non-moderator the query would exclude unapproved posts that would not be presented to moderators.