Skip to:
Content
Pages
Categories
Search
Top
Bottom

Topic paging issue


  • Tom(dB)
    Participant

    @tomdebruin

    I’ve just had a report from one of my forum users saying that occasionally the topic will not return the actual number of posts, and therefore the last page link doesn’t show up.

    In the example there was a topic with 122 posts over 4 pages. The forum stated there were 120 posts over three pages. Latest reply listed the last person who posted but had a link to the last post on page 3 (post 120), and not post 122 on page 4.

    I deleted one post and then undeleted it. This solved the problem.

    I’m not sure what caused it, or how to replicate it. Could this be a bug in bbP or perhaps something I’m doing?

Viewing 25 replies - 1 through 25 (of 48 total)

  • chrishajer
    Participant

    @chrishajer

    Have you tried recounting in the admin?


    Tom(dB)
    Participant

    @tomdebruin

    i’ll give that a go. cheers.


    Tom(dB)
    Participant

    @tomdebruin

    Unfortunately these options:

    Count posts of every topic

    Count tags for every topic

    Count topics for every tag

    return fatal errors – Fatal error: Allowed memory size of 25165824 bytes exhausted (tried to allocate 35 bytes) (and many others).

    Though we do have 550,000 posts.


    _ck_
    Participant

    @_ck_

    The way bbPress does recounts is horribly bad to this very day, even in 1.0

    http://trac.bbpress.org/ticket/1146

    It does a separate query for every topic instead of doing it all internally via mysql.

    Be sure to only do one kind of recount per attempt, don’t check them all on an active forum or you’ll make your mysql cry and your php timeout.

    I might have to try to write the special mysql query for you.


    chrishajer
    Participant

    @chrishajer

    Only 24 MB of RAM for PHP?


    Tom(dB)
    Participant

    @tomdebruin

    So to use just one of the recount functions on a forum with a half million topics, you currently pull an array of the topic id’s several megabytes in size into ram, then proceed to use 500,000 x 3 = 1.5 MILLION QUERIES to update the meta.

    that’s me! Thanks _ck_.

    Is this the same issue that’s causing the paging to be wrong? The user has just reported:

    It commonly happens with the 41st post on a thread, where you if you click on “latest post” link you get sent to the 40th post at the bottom of page 1, with no link to page 2 (note in the example I sent you “latest post” sent you to the bottom of page 3).


    _ck_
    Participant

    @_ck_

    If you are using my “topics per page” plugin there may be a bug as far as which page you are sent to. Are you using that plugin?

    I guess it could also calculate the page incorrectly if there are deleted posts and the post count is wrong.

    You definitely need to accomplish a recount somehow. Let me study the mysql.


    _ck_
    Participant

    @_ck_

    I’ve now made a plugin to do a few kinds of fast recounting much faster than bbPress does it and with only a few queries vs the hundreds or thousands bbPress can do.

    I highly recommend you backup your database first since I’ve only barely tested it (in theory if it went wrong you could do the recount the long way via the regular functions)

    http://bbshowcase.org/plugins/fast-recount.zip

    The new recount selections will appear under the regular recount menu.

    DO NOT use this plugin under bbPress 1.0, it’s assumes bbPress 0.9 table structures.


    Tom(dB)
    Participant

    @tomdebruin

    Thanks _ck_. Unfortunately I’m using v1 so can’t put your plugin into practice. Although I’m sure (I hope) it will soon be featured in the software itself.

    I may have a look at your plugin and see if it’s straightforward to amend for v1.


    _ck_
    Participant

    @_ck_

    Technically you can just NOT check the “count deleted posts” and still use part of the recount functions on 1.0, which has a different meta table and I haven’t written it’s query yet.


    Tom(dB)
    Participant

    @tomdebruin

    Only 24 MB of RAM for PHP?

    8mb is a standard installation. Shouldn’t 24mb be enough?


    _ck_
    Participant

    @_ck_

    24mb is fine. Remember that’s per PHP instance, it’s not shared.

    My method does it all inside mysql anyway so the problem will be eliminated. If mysql has to, it will make a temporary table on disk to solve the query and it all happens in high speed compiled C which will always be faster than PHP (even with an opcode cache).


    e-motion
    Participant

    @e-motion

    I am having this problem too. You can check it at:

    http://e-motion.lt/bbpress/topic/12/page/3

    Go to page 4. The thread has one post deleted – #24.

    I am using bbPress 1.0.2.


    _ck_
    Participant

    @_ck_

    Did you do a recount?


    e-motion
    Participant

    @e-motion

    _ck_,

    Yes, I’ve tried to do a recount, but it had no effect on this issue.

    For this example, unfortunately, the thread in given link is an active discussion and the problem vanished when one reply was written. It will reappear when someone writes a reply last on that page. I wonder how it will be with two deleted posts, not one…


    _ck_
    Participant

    @_ck_

    Are you using the topics per page plugin?


    e-motion
    Participant

    @e-motion

    No, I do not. I have following plugins:

    Akismet

    Allow Images

    Avatar Upload

    BBcode Buttons Toolbar

    BBcode Lite

    bbPM

    BBVideo

    Bozo Users

    Hello Louie

    Human Test for bbPress

    Instant Password

    Skip Akismet

    SourceCode Highlighter


    _ck_
    Participant

    @_ck_

    I must be missing the problem here.

    The “latest reply” link works.

    When I am on page 3, the page 4 link works.

    What specifically is not working?

    Are you saying the problem is intermittent?

    ps. I use an ebike with a custom lifepo4 battery :-)

    Oh wait, I see what you saying now

    he problem vanished when one reply was written.

    It will reappear when someone writes a reply last on that page.

    so it’s an even/odd problem

    if there are an even number of posts, it works,

    if there is an uneven number, it does not work

    Did you try the trick of deleting one post and then undeleting it?

    There must be a bug in the way bbPress calculates post-position when there are deleted posts. I wonder if it’s specific to 1.x


    _ck_
    Participant

    @_ck_

    You know what, this is an inherit flaw with bbpress that I think I mentioned elsewhere years ago.

    It never recalculates post-position when there are deleted posts, yet it relies on that post-position to find a specific posts’s page.

    See this is how it calculates the page

    function get_post_link( $post_id = 0 ) {
    $bb_post = bb_get_post( get_post_id( $post_id ) );
    >>>>>> $page = bb_get_page_number( $bb_post->post_position );
    return apply_filters( 'get_post_link', get_topic_link( $bb_post->topic_id, $page ) . "#post-$bb_post->post_id", $bb_post->post_id );
    }

    and this is how it calculates that page

    return intval( ceil( $item / $per_page ) );

    so it’s $bb_post->post_position / $per_page

    always, regardless if there are deleted posts in the way, which is why it can be “short” when calculating the last page(s) on a longer topic with deleted posts.

    The solution is that post-position has to be recalculated when a post is deleted. The only side effect is that for admin, jumping directly to a deleted post would not work, you’d have to find it manually.

    bbPress never, ever, re-calculates post-position, even on a recount, if I am not mistaken.

    There is one tiny work-around we can do.

    For the LAST POST calculation, we can intercept that and subtract the number of deleted posts from the post-position. Hmm, actually wait, is it subtract or add. I have to investigate this a bit and think out the logic.


    _ck_
    Participant

    @_ck_

    I need to see this problem in action.

    If you can, put another post on there to trigger it?


    _ck_
    Participant

    @_ck_

    Here’s a simplified example of what I think is happening internally.

    Let’s say for ease of understanding there are TWO posts per page.

    And there are 7 posts in this particular topic example

    |1 2| – |3 4| – |5 6| – |7|

    so there are 4 pages (each | | is a page)

    In this example, the post numbers are also the post-position.

    Now let’s say a mod deletes post number 4

    |1 2| – |3 5| – |6 7|

    Should only be three pages.

    But bbPress is stupid by default, post-position is never recalculated so those post numbers still represent post position in this example.

    bbPress DOES track number of posts in a topic, even when deleted.

    So requesting a link to the last post in the topic, regardless of post-position, WILL be calculated correctly, and return page 3.

    However, if it specifically asks for a direct link to post 7 and not the last post in the topic, this is what happens.

    Post 7 is post-position 7

    posts per page is 2 per page

    ceil( $post_position / $per_page )

    7 / 2 = 3.5, ceil of 3.5 = 4

    So it will ask for page 4

    Page 4 does not exist in the topic.

    The link may be created but the link is bogus and will not work, it will either return you to the first page of the topic, or maybe the front page of the entire forum.


    _ck_
    Participant

    @_ck_

    I have a little trick to workaround this problem, at least when bbpress requests a link for the post that happens to be the last post in the topic.

    I will write a filter for when get_post_link is requested, it will check the post id# – if it happens to be the last post in the topic (stored in topic_last_post_id) it will instead route the request to the more accurate get_topic_last_post_link


    e-motion
    Participant

    @e-motion

    I am now trying to recreate the problem. I was unable to do so on new topic and can’t remember exactly what I did last time. It just recounts all post numbers and everything works fine. It is stupid of me, but somehow I think that I may have tampered with the post physically – on phpMyAdmin. I am not sure about this, I do lots of stupid things.

    I have now temporarily closed this topic (it is most active one in my whole forum) and added some posts to replicate the problem:

    http://e-motion.lt/bbpress/topic/12?replies=80&message=closed

    Forum says there are 81 posts and 5 pages. On page #2 post #24 is missing.

    Page #5 is “empty”. If I unlock the topic, reply form is on page #5 and not #4, where the last post is.

    Sorry, I am not so good with CMS-related stuff.. I do know some PHP and MySQL, but some basic help may be needed.

    P.S. Very nice to hear you also have an e-bike! I have been riding this one for a while: http://www.youtube.com/watch?v=fXsE5NNfC7w

    And hopefully will ride a DIY electric scooter in couple of weeks.


    _ck_
    Participant

    @_ck_

    Okay I see the problem now with the next page link on page 4, which takes it to an empty page.

    That in theory is a slightly different problem.

    We can see that bbpress thinks there are 81 posts (visible) in the topic.

    And there are 20 posts per page on the default setup.

    So yeah, there should be a page 5.

    Somehow post 81 is showing on page 4

    page 1: 1-20

    page 2: 21-41 <<<< mistake, post-position 24 is missing

    page 3: 42-61

    page 4: 62-81

    Something started going wrong on page 2 I think?

    It should start at 21 and go to 40.

    Let me go back and look at that.

    Yup, there is a gap for 23-25

    That means that number count is showing post-position and 24 has been deleted.

    So the example I show above with the pages, imagine post 24 is post 4 from the example.

    bbPress is being stupid and rounding up for some reason.

    There aren’t 81 posts in the topic, there are 80.


    _ck_
    Participant

    @_ck_

    You’ve definitely done a recount in the admin section?

    Because the 81 on the topic list is very wrong.

    Do a recount in the admin.

    If it still shows 81, I want you to delete one of those last filler posts you made and then undelete it. That will force a recount.

Viewing 25 replies - 1 through 25 (of 48 total)

You must be logged in to reply to this topic.