Re: Unread Topics
Err, no. I read your description here. I thought about that approach before but I like the time-based implementation, especially as my hosting is a bit creaky (and edit: having come to the finish of this post, I realise that it’s actually not that bad at all! Maybe it is a good idea, especially as it’s a lot more convenient). It’s good that you’ve done it though, and cool that you’re sharing it (in the face of adversity ). I hope you don’t mind; here’s some suggested changes that could speed things up a lot.
For installing the table, you may want to use
bb_dbDelta() (should work exactly as wp’s implementation: https://codex.wordpress.org/Creating_Tables_with_Plugins ).
There are also a lot of queries made that you could probably avoid. For example, in the topic listing the current topic will be in the global $topic, and you can get its last_post_id by this:
$last_post_in_topic = $topic->topic_last_post;
You can do the same for the number of posts.
Every column in the table will be available as a member variable (don’t know how familiar you are with PHP? Member variables are just like above, $member->!!!member_variable!!!) – that’s true for users, posts, topics and forums alike. (Meta entries are too, if there’s an entry topic_colour in the topicmeta table you can call it by $topic->topic_colour.)
Right now you’re making at least three additional queries per topic:
if ( utplugin_is_topic_unread($topic, $user) || utplugin_is_topic_new($topic, $user) )
utplugin_is_topic_unread() makes three queries. If it’s not unread, it’ll check if it’s new, too, which is another two. For the default 30 topics, that’s 90 – 150 additional database queries per single view of a page. Since db queries are usually the bottlenecks in website speed that could be a problem. (_ck_ would probably blow an artery.)
By using the already-queried stuff from
global $topic you can cut that down to one or two topics per query. Also, in utplugin_is_topic_new() you’re using exactly the same value again, but making a new query for it, if I see that right. You could either move the check to utplugin_is_topic_unread() (which would return true for unread and for new) or make that a global itself.
That would make it at most one query per topic.
Finally, IIRC data for all topics on the page is being called in a single query. If you can find the right filter or hook, you may find that you can get all the relevant topic_ids at once, at the start, then do a _single_ query on your table that gets data for all of them, make that a static (so it’s preserved every time the function is called) and use that data every time. Then the overhead generated by your plugin wouldn’t even be so bad.