Refresh category table counts sometimes for small categories
authorAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 5 Sep 2008 16:31:34 +0000 (16:31 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 5 Sep 2008 16:31:34 +0000 (16:31 +0000)
When someone views a category page, if the number of retrieved pages is the whole category (no from= or until=, 200 or less retrieved), and that number doesn't match the number in the category table, we already detect that this is wrong and ignore the bogus category table number.  Now the software also refreshes the bogus category counts in the database in this case, which should be pretty much instantaneous since it has less than 200 entries.

This adds no overhead for categories that have correct counts, and fixes the most visible case when category counts are wrong: small categories, when you can easily count the pages.

includes/CategoryPage.php

index 92e4e27..bf67f88 100644 (file)
@@ -500,8 +500,12 @@ class CategoryViewer {
                        # Case 1: seems sane.
                        $totalcnt = $dbcnt;
                } elseif($totalrescnt < $this->limit && !$this->from && !$this->until){
-                       # Case 2: not sane, but salvageable.
+                       # Case 2: not sane, but salvageable.  Use the number of results.
+                       # Since there are fewer than 200, we can also take this opportunity
+                       # to refresh the incorrect category table entry -- which should be
+                       # quick due to the small number of entries.
                        $totalcnt = $rescnt;
+                       $this->cat->refreshCounts();
                } else {
                        # Case 3: hopeless.  Don't give a total count at all.
                        return wfMsgExt("category-$type-count-limited", 'parse',