Unread Post Count

Unread Post Count 1.2.0

No permission to download
Hey Chris,

Didn't really look into this too much, but every time this ran for a user it caused a fairly substantial bump in page generation (about an additional second) from this query:

Code:
            SELECT thread.thread_id, post.post_id
            FROM xf_post AS post
            INNER JOIN xf_thread AS thread ON
                (post.thread_id = thread.thread_id AND thread.node_id IN (' . $this->_getDb()->quote($forumIds) . '))
            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 = ?)
            LEFT JOIN xf_forum_read AS forum_read ON
                (forum_read.node_id = thread.node_id AND forum_read.user_id = ?)
            WHERE post.post_date > ?
            AND post.message_state = \'visible\'
            AND thread.discussion_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)
            )

Is there a reason it selects the thread id and post id instead of just doing a count? Keeping in mind, I didn't really look into what else this add-on does so I may be completely wrong in thinking that would work :)
 
It's grouped by thread ID and then cached IIRC. That way when a user views a thread we just unset that key to adjust the count rather than recounting (which would be worse).

Oddly some forums handle this better than others. So it may come down to the MySQL configuration and tuning. It is however a generally evil query but one of necessity to perform the task.
 
Ah, makes sense. I've changed this line:

Code:
$autoReadDate = XenForo_Application::$time - (XenForo_Application::get('options')->readMarkingDataLifetime * 86400);

to this:
Code:
$autoReadDate = XenForo_Application::$time - (7 * 86400);

Which reduced it to a max of 17k threads, which helped substantially :)
 
That's sort of the point. The unread post count is supposed to mimic the number of new posts there are.

But if it works it's all good.
 
Hey Chris,

I've installed the addon and it's showing the unread post indicator on the default style, however the style I've got doesn't appear to show it.

Is there anything I can add templateside that can bring this joy to everyone?
 
I'm not sure. It works on most custom styles I've seen so it should just work bere.

Most likely cause is the style designer has changed something in the template which makes the template modification not work. They may be better placed to identify the issue.
 
Just in case someone else wants this to work in Velour, you have to create a new template modification. This is due to navTabs and tabLinks being split into 2 different templates. Here is what you need to put into your new template modification:

Template: tabLinks

Modification Key: tabLinksUnreadCount

Search Type: Regular Expression

Find: /href="{xen:link 'fi(.*?)s}}/is

Replace: $0 <xen:include template="unread_posts_count" />

Automatically apply this modification: on

Add-on: empty


Don't worry, it'll say that template is not found, this is correct.
 
Last edited:
Replace EWRporta_Navtabs template content with
Code:
<ul class="secondaryContent blockLinksList">
    <xen:if is="{$visitor.user_id}"><li><a href="{xen:link 'watched/threads'}">{xen:phrase watched_threads}</a></li></xen:if>
    <li><a href="{xen:link 'recent-activity'}">{xen:phrase recent_activity}</a></li>
    <li><a href="{xen:link 'find-new/posts'}" rel="nofollow">{xen:if $visitor.user_id, {xen:phrase new_posts}, {xen:phrase recent_posts}}<xen:include template="unread_posts_count" /></a></li>
    <xen:if is="{$perms.custom}">
        <li style="width: 50px; height: 10px;"></li>
        <li><a href="{xen:link 'portal/blocks'}">{xen:phrase customize_this_page}</a></li>
    </xen:if>
</ul>
Thanks for this, I added the code <xen:include template="unread_posts_count" /> and it's working on Xenporta 2 as well. :)
 
This showed today

Zend_Db_Statement_Mysqli->_prepare() in Zend/Db/Statement.php at line 115
Zend_Db_Statement->__construct() in Zend/Db/Adapter/Mysqli.php at line 381
Zend_Db_Adapter_Mysqli->prepare() in Zend/Db/Adapter/Abstract.php at line 478
Zend_Db_Adapter_Abstract->query() in Zend/Db/Adapter/Abstract.php at line 734
Zend_Db_Adapter_Abstract->fetchAll() in UnreadPostCount/Model/Unread.php at line 35
UnreadPostCount_Model_Unread->getUnreadPostCount() in UnreadPostCount/Listener.php at line 36
UnreadPostCount_Listener::controllerPreDispatch()
call_user_func_array() in XenForo/CodeEvent.php at line 58
XenForo_CodeEvent::fire() in XenForo/Controller.php at line 313
XenForo_Controller->preDispatch() in XenForo/FrontController.php at line 350
XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 134
XenForo_FrontController->run() in /home/rolep755/public_html/index.php at line 1

I deactivated unread Post count and now this shows

Notice: Undefined index: style_id in /home/-x-/public_html/library/XenForo/Dependencies/Public.php on line 305


Can someone help please?
 
What's the full error for the stack trace that shows there?

Notice: Undefined index: style_id in /home/-x-/public_html/library/XenForo/Dependencies/Public.php on line 305
This seems to be unrelated, at least. Have you had problems installing, upgrading or uninstalling a style?
 
Well I did not touch my style information at all. So I have no idea how or whyy the style has messed up. I even went to my "Appearances" section and there is nothing there, even the basic xenforo style is not in the list.
Now it shows this error.

Server Error
Undefined index: style_id

  1. XenForo_Application::handlePhpError() in XenForo/Model/Style.php at line 70
  2. XenForo_Model_Style->getAllStyles() in XenForo/Model/StyleProperty.php at line 568
  3. XenForo_Model_StyleProperty->rebuildPropertyCacheInStyleAndChildren() in XenForo/Model/StyleProperty.php at line 2441
  4. XenForo_Model_StyleProperty->importStylePropertiesFromArray() in XenForo/Model/StyleProperty.php at line 2312
  5. XenForo_Model_StyleProperty->importStylePropertyXml() in XenForo/Model/StyleProperty.php at line 2245
  6. XenForo_Model_StyleProperty->importStylePropertyDevelopmentXml() in XenForo/Deferred/ImportMasterData.php at line 26
  7. XenForo_Deferred_ImportMasterData->execute() in XenForo/Deferred/Atomic.php at line 66
  8. XenForo_Deferred_Atomic->execute() in XenForo/Model/Deferred.php at line 295
  9. XenForo_Model_Deferred->runDeferred() in XenForo/Model/Deferred.php at line 429
  10. XenForo_Model_Deferred->_runInternal() in XenForo/Model/Deferred.php at line 355
  11. XenForo_Model_Deferred->runByUniqueKey() in XenForo/Install/Controller/Abstract.php at line 34
  12. XenForo_Install_Controller_Abstract->_manualDeferredRunner() in XenForo/Install/Controller/Upgrade.php at line 221
  13. XenForo_Install_Controller_Upgrade->actionRunDeferred() in XenForo/FrontController.php at line 351
  14. XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 134
  15. XenForo_FrontController->run() in /home/rolep755/public_html/install/index.php at line 18


Dont really know where to go from here
 
I think you would be best sticking with the ticket you have open. The style_id error is certainly unrelated to this add-on, and the Unknown column 'post.post_id' in 'field list' error (which I think is the missing line from the error in your previous post) isn't directly related to the add-on either; it actually suggests the post_id column is missing from the xf_post table.
 
@Chris D How can I make a notice saying if you have a large number, you must mark forum as read?
Seems like there is nothing in notice criterias that does this?

edit// nvm, got it :)
 
Last edited:
Top Bottom