When a user visits the main forums page the number of new posts within a particular forum, listed below the total number of posts, is sometimes wrong. I don't believe it is ever too low, but it has even been higher than the total number of posts actually in the forum. With Advanced Forum turned off, the counts are accurate. The forum on our site is at http://www.antirdearg.com/forum
I have uploaded screenshots of the problem, the view inside the bottom forum and the view with AF turned off. I'm not much good with PHP, so I took the simplistic approach and updated to the newest alpha to see if that fixed it, but it is still happening. Any ideas on where to start troubleshooting this?
Comments
Comment #1
movinr8along commentedI investigated this issue http://drupal.org/node/284392 and this issue http://drupal.org/node/113611 and while it seems likely this is related to db_rewrite_sql issues, the issues addressed in 284392 are fixed in Drupal 6.16 and the fix in 56 of 113611 did not fix this problem. Since the problem does not occur with Advanced Forum disabled and I have disabled all access control modules and the problem persists, it seems likely that the issue fixed in core with 113611, post 56, exists in Advanced Forum, but no patch has been prepared. Any thoughts? Am I even on the right track?
Comment #2
michelleThis is something that will take some time to dig into so may be a while before I can give you a proper response.
Michelle
Comment #3
movinr8along commentedThanks for communicating. It's not urgent for me as this is a simple sports group site, but I'll look at it again in a day or two and see if I get any further. I've identified the section of code that does the count, but haven't messed with modifying it or tracking down how it interacts with everything else yet. Right now I'm looking at this issue http://drupal.org/node/349675#comment-2350532 to see if it can point me in the right direction to fix this. It's not the same issue (root user sees incorrect posts as well) and it doesn't happen every time, but I'll check it out.
Comment #4
movinr8along commentedThe number of miscounted posts is a bit mysterious. Right now it seems that new comments are pretty consistently counted twice, regardless of the number of roles a user is assigned (thought it might be related to roles, but removing additional roles didn't help). But using an account that hasn't read any threads for a while and is only an authenticated user, the number of new posts is not twice the actual number of new posts. Once inside a particular forum, the count of the number of new posts in each individual thread is always right. It's just the count at the base /forum page summarizing the number of new posts to the threads in each of the forums that is wrong. I am not using node comment and the 1st post, the node, seems to never be counted twice (the new topics column is always correct and if a new topic is created with no comments, the new posts count will be correct, i.e. 1).
Comment #5
michelleI can't reproduce this. I went through all my forums on the site that's using core comment, added up the number of new comments then added the number of new topics and every time it matched the number of new posts listed on the master forum listing. You say the counts are accurate with AF turned off but that doesn't make sense since the total new posts count is an AF only feature.
None of the links to your screenshots are working. Do you have a test account I could use that is having the problem?
Michelle
Comment #6
movinr8along commentedYou are right, of course, there is no new posts count without AF so it works. I have sent you login information through your contact page at shellmultimedia for an account where you can see the problem. Thanks for looking at this so quickly.
Here are the corrected links from above, for anyone else who may find this later or be following along (left out the subdirectory):
Problem
Inside the last forum
Without AF
Comment #7
movinr8along commentedForgot to update status
Comment #8
michelleOk, that's really weird... They're definitely off but I can't figure out what could be causing that. This is the code to get the number of new comments and then the number of new topics is added to that:
There's not much to it... Just a query, really. You said you're not using nodecomment so it would be the second query running.
I'm stumped at the moment... Unless it's some SQL difference maybe? What sort of SQL are you running and what version?
Michelle
Comment #9
movinr8along commentedmysql Ver 14.14 Distrib 5.1.45, for unknown-linux-gnu (x86_64) using readline 5.1
I had identified the section and wanted to play with the code, but my drupal/PHP ignorance was making the %d a mystery. I have now educated myself on PHP placeholders and messed with with the query further in SQL. Simply changing this:
$sql = "SELECT COUNT(c.cid) AS count, f.tidto this:
$sql = "SELECT COUNT(DISTINCT(c.cid)) AS count, f.tidfixes it, but I haven't tested for any other problems.
Comment #10
michelleDistinct fixes it? Now that's bizarre... Why/how do you have duplicate comments? Isn't cid a primary key?
Michelle
Comment #11
movinr8along commentedWell, I messed around with it for a while now and I think I finally found it. It appears the forum table has multiple entries for some of the nids which have the same tid, but different vids. One thread has 8 different vid numbers, so a comment posted there gets counted 8 times. Most only have one or two vid numbers. Why would a forum topic get multiple vids?
Comment #12
movinr8along commentedI have to run right now and I haven't tested this yet, but something along these lines may be viable to avoid using DISTINCT:
Comment #13
movinr8along commentedThis code:
And this code:
both seem to match the actual new comments in the topics, EXCEPT they assume that the first value of f.tid for a given f.nid is correct, which it generally won't be. At least one reason for multiple vids being generated is if a topic is moved from one forum to another. With the DISTINCT route, this topic appears to be counted twice, once in the original forum and again in the new forum. With the GROUP BY subquery the topic appears to be counted in it's original forum, not the new one. I haven't solved that yet.
Comment #14
movinr8along commentedOkay, had another minute to look at it (and this has turned into a bit of a fun puzzle) and this seems to get the right results, but could probably be simplified.
It seems to me the php version should be:
But in practice, the count gets bumped +1 for every thread in which the initial post has not been read. Does that make sense/look right to you Michelle?
Edit: The +1 bump doesn't always happen with new topics. For user 4, the one I sent you, it happens in tid 4 and 1, but not in 9. The number returned is correct when I do the query in mySQL, but the result returned by my php above is not so perfect.
Comment #16
mr.andrey commentedsubscribing...
Comment #17
gmiossi commentedsubscribing
Comment #18
michelleOk, fixed the problem with some help on IRC.
Michelle
Comment #19
mr.andrey commentedWhat about 6-1 dev? It still has the problem. I don't think it's due to revisions... I have those turned off. Should I start a new thread?
Comment #20
michelle1.x likely has the same issue. I set it to be ported. If you don't have revisions on then I have no idea. The only issues I'm aware of with this is revisions & forum access. If it's not one of those, you can start a new issue but 1.x issues without a fix attached aren't getting much attention. I just don't have the time.
Michelle
Comment #21
michelleCommitted to 1.x.
Michelle