Unread Post Count

Unread Post Count 1.2.0

No permission to download
@Chris Deeming

Just looking at the queries being run on my pages, and what is taking the longest time. This add-on is taking the most time. Looking at the query, it can be sped up by replacing the INNER JOIN with a LEFT JOIN

Before
Code:
mysql> SELECT COUNT(*)
    -> FROM xf_post AS post
    -> INNER JOIN xf_thread AS thread ON
    -> (post.thread_id = thread.thread_id AND thread.node_id IN (64, 103, 132, 139, 7, 2, 44, 57, 8, 89, 23, 21, 152, 27, 93, 112, 76, 90, 91, 113, 111, 117, 163, 171, 19, 67, 45, 118, 1, 14, 3, 22, 11, 78, 77, 79, 148, 25, 39, 81, 154, 94, 161, 115, 61, 108, 62, 86, 104, 87, 88, 105, 84, 59, 49, 123, 110, 178, 106, 124, 131, 136, 130, 120, 150, 160, 164, 167, 6, 52, 54, 53, 174, 51, 70, 133, 16, 12, 82, 135, 149, 46, 126, 175, 176, 162, 166, 168, 170, 173, 125, 147, 177, 155, 156, 157, 158, 159, 119))
    -> INNER JOIN xf_forum AS forum ON
    -> (forum.node_id = thread.node_id AND forum.find_new = 1)
    -> LEFT JOIN xf_thread_read AS thread_read ON
    -> (thread_read.thread_id = thread.thread_id AND thread_read.user_id = 1)
    -> LEFT JOIN xf_forum_read AS forum_read ON
    -> (forum_read.node_id = thread.node_id AND forum_read.user_id = 1)
    -> WHERE post.post_date > 1366167427
    -> AND post.message_state = 'visible'
    -> AND post.post_date > GREATEST(
    -> IF (thread_read.thread_read_date IS NULL, 0, thread_read.thread_read_date),
    -> IF (forum_read.forum_read_date IS NULL, 0, forum_read.forum_read_date)
    -> )
    -> ;
+----------+
| COUNT(*) |
+----------+
|      72 |
+----------+
1 row in set (0.34 sec)

After
Code:
mysql> SELECT COUNT(*)
    -> FROM xf_post AS post
    -> LEFT JOIN xf_thread AS thread ON
    -> (post.thread_id = thread.thread_id AND thread.node_id IN (64, 103, 132, 139, 7, 2, 44, 57, 8, 89, 23, 21, 152, 27, 93, 112, 76, 90, 91, 113, 111, 117, 163, 171, 19, 67, 45, 118, 1, 14, 3, 22, 11, 78, 77, 79, 148, 25, 39, 81, 154, 94, 161, 115, 61, 108, 62, 86, 104, 87, 88, 105, 84, 59, 49, 123, 110, 178, 106, 124, 131, 136, 130, 120, 150, 160, 164, 167, 6, 52, 54, 53, 174, 51, 70, 133, 16, 12, 82, 135, 149, 46, 126, 175, 176, 162, 166, 168, 170, 173, 125, 147, 177, 155, 156, 157, 158, 159, 119))
    -> LEFT JOIN xf_forum AS forum ON
    -> (forum.node_id = thread.node_id AND forum.find_new = 1)
    -> LEFT JOIN xf_thread_read AS thread_read ON
    -> (thread_read.thread_id = thread.thread_id AND thread_read.user_id = 1)
    -> LEFT JOIN xf_forum_read AS forum_read ON
    -> (forum_read.node_id = thread.node_id AND forum_read.user_id = 1)
    -> WHERE post.post_date > 1366167427
    -> AND post.message_state = 'visible'
    -> AND post.post_date > GREATEST(
    -> IF (thread_read.thread_read_date IS NULL, 0, thread_read.thread_read_date),
    -> IF (forum_read.forum_read_date IS NULL, 0, forum_read.forum_read_date)
    -> );
+----------+
| COUNT(*) |
+----------+
|      72 |
+----------+
1 row in set (0.10 sec)
 
Actually, don't make that change to the SQL query.

When you change it to LEFT JOIN, it's including posts from forums members don't have access to.
 
Anyone wanting to put this somewhere else might want to try pasting this at the desired location:

Code:
<xen:include template="unread_posts_count" />
So I did this and added it to my taigachat page, but it only added the unread post red alert box. I want that but also the new posts text/link. Can you help me add that as well?

Edit, got that added, but the notification red button is off center as seen here. Any way to fix that? Here is my code for that template:

Code:
<ul class="secondaryContent blockLinksList">
    <li><a href="{xen:link '{$taigachat.route}'}">{xen:phrase dark_full_view}</a></li>
    <xen:if is="{$taigachat.popupenabled}">
        <li><a href="{xen:link '{$taigachat.route}/popup'}" class="taigachat_popup_link" target="_blank">{xen:phrase dark_popup}</a></li>
    </xen:if>
<li><a href="{xen:link 'find-new/posts'}" rel="nofollow">{xen:if $visitor.user_id, {xen:phrase new_posts}, {xen:phrase recent_posts}}</a></li>

    <xen:include template="unread_posts_count" />
</ul>

<script type="text/javascript">
// <![CDATA[
    $(document).ready(function(){
        $(".taigachat_popup_link").click(function(e){
            window.open(this.href, 'taigachat_popup_window', 'width=900,height=700,menubar=no,toolbar=no,location=no,status=no,resizable=yes,scrollbars=yes,personalbar=no,dialog=no');
            e.preventDefault();
            return false;
        });
    });
// ]]>
</script>
 
Last edited:
Just add the link next to it:

Code:
<a href="http://address.to.whatever.com">Link to whatever</a><xen:include template="unread_posts_count" />
 
Code:
.taigachatTabLinks .postItemCount {
    position: absolute;
    top: 10px;
}

I don't know why, but other alignment methods won't work. But this seems to. Add the above to EXTRA.css.
 
One of our Mods has the Unread Post Count showing as 5 but when he clicks on What's New? it tells him he has no unread threads. How does this happen?
 
I actually think it's related to moderated and soft deleted posts.

I've been meaning to check out the code. Something somewhere is including these in the count.
 
This is very strange, but this add-on killed my server on a daily basis.

mysql ended up with ~300 % cpu and had to be restarted...
 
Love the plugin, thanks :) One question. I'd like the notifier to insert itself AFTER the </a> tag for the "new posts" link. I've set those links to be underlined, but I don't want it extending into the unread post count.

Can you help me modify the regular expression used? I'm fairly new to regex..

Edit, got it, but it dropped it to a new line.. and it seems anything I add after </a> in the navigation template drops down a line. But I guess that's an issue outside this add-in. ;) Still, if you have any pointers I'll take em!
 
Last edited:
Back
Top Bottom