Recent Topics

0.9.1 counts posts incorrectly

Started by on Nov 11, 2005 – Contents updated: Nov 11, 2005

Nov 11, 2005 20:16    

0.9.1 has a bad SELECT ... JOIN which will cause it to count posts with more than one category as multiple posts.

You can see this when browsing in "x posts per page" mode, or when browsing posts in edit mode in backoffice.

To fix, use the SQL keyword "DISTINCT" in front of "ID" in the "SELECT" in file blogs/b2evocore/_class_itemlist.php at line 529.

Here's the "diff -u" patch:

Code

--- /root/b2evolution/blogs/b2evocore/_class_itemlist.php       2005-09-13 16:11:02.000000000 -0400
+++ _class_itemlist.php 2005-11-11 13:49:44.602951787 -0500
@@ -526,7 +526,7 @@
                                $this->request .= ' WHERE 0';
                        }
  
-                       $this->count_request = "SELECT COUNT(ID)
+                       $this->count_request = "SELECT COUNT(DISTINCT ID)
                                                                               FROM ($tableposts INNER JOIN $tablepostcats ON ID = postcat_post_ID)
                                                                               INNER JOIN $tablecategories ON postcat_cat_ID = cat_ID
                                                                               ".$where;

Nov 16, 2005 03:38

Thanks for the patch, but I cannot reproduce it.

Shouldn't it show more than 5 posts here then?

The trick is to make a post then mess around with the categories.

Add two categories. Add a post assigning it to two or more. Then add another category. Edit the post, changing one old category for another.

The basically causes a state where the b2evolution database table evo_postcats contains two or more rows where the left side (the post id) is repeated for each category.

Nov 16, 2005 08:47

I still cannot reproduce it.

Additionally there's a PRIMARY/UNIQUE INDEX on those fields in T_postcats (evo_postcats).

Could you take a look if you have this index?

Nov 20, 2005 04:23

I've added a TODO in the code about this, but feedback and the real cause would be very welcome.. :)

Nov 29, 2005 14:15

I've changed it in CVS for Phoenix, because I've just seen it happening for myself.

Jan 05, 2006 16:55

Man, get catch by nitfol.

I've been going crazy trying to figure out why my post/page counts were way off whenever I made a post in multiple categories. I've searched these forums for months looking for the fix, and now finally I've found it, thanks to nitfol.

:D


Form is loading...

CMS + forums – This forum is powered by b2evolution CMS, a complete engine for your website.