From 3eff786201989b21ebdda0985b64e7aa59a55672 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Mon, 11 Nov 2013 13:35:43 +1100 Subject: [PATCH] In Special:AllPages, limit the size of hierarchical lists Traversal of the entire page list by spidering the top levels is thought to require O(N^3) DB CPU time where N is the number of pages on the wiki. So introduce a limit for the size of such lists, as measured by the pre-existing estimateRowCount(). Bug: 56840 Change-Id: I189ba71de869496a36f49283ec6dce7bbdfccd73 --- includes/specials/SpecialAllpages.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/includes/specials/SpecialAllpages.php b/includes/specials/SpecialAllpages.php index a08204936a..388705d0c2 100644 --- a/includes/specials/SpecialAllpages.php +++ b/includes/specials/SpecialAllpages.php @@ -49,6 +49,16 @@ class SpecialAllpages extends IncludableSpecialPage { */ protected $maxPageLength = 70; + /** + * Maximum number of pages in a hierarchical ("top level") list. + * + * Traversal of the entire page list by spidering the top levels is thought + * to require O(N^3) DB CPU time where N is the number of pages on the wiki. + * See bug 56840. If this limit is exceeded, the behaviour becomes like a + * simple alphabetic pager. + */ + protected $maxTopLevelPages = 50000; + /** * Determines, which message describes the input field 'nsfrom'. * @@ -201,6 +211,14 @@ class SpecialAllpages extends IncludableSpecialPage { $lines = $wgMemc->get( $key ); $count = $dbr->estimateRowCount( 'page', '*', $where, __METHOD__ ); + + // Don't show a hierarchical list if the number of pages is very large, + // since generating it will cause a lot of scanning + if ( $count > $this->maxTopLevelPages ) { + $this->showChunk( $namespace, $from, $to, $hideredirects ); + return; + } + $maxPerSubpage = intval( $count / $this->maxLineCount ); $maxPerSubpage = max( $maxPerSubpage, $this->maxPerPage ); -- 2.20.1