r80008 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80007‎ | r80008 | r80009 >
Date:14:17, 11 January 2011
Author:nikerabbit
Status:ok
Tags:
Comment:
Attack on query bloat. The permissions checks were doing few hundred queries on page view.

For every post(?) it created a new title with same name to check if use can create it.
Changed to cache the results locally per user.
Modified paths:
  • /trunk/extensions/LiquidThreads/classes/Thread.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/classes/Thread.php
@@ -1543,14 +1543,7 @@
15441544 }
15451545 }
15461546
1547 - $testTitle = Title::makeTitleSafe( NS_LQT_THREAD, 'test' );
1548 - if ( ! $testTitle->userCan( 'create' ) ||
1549 - ! $testTitle->userCan( 'edit' ) )
1550 - {
1551 - return false;
1552 - }
1553 -
1554 - return true;
 1547+ return self::canUserCreateThreads( $user );
15551548 }
15561549
15571550 public static function canUserPost( $user, $talkpage ) {
@@ -1562,14 +1555,20 @@
15631556 }
15641557 }
15651558
1566 - $testTitle = Title::makeTitleSafe( NS_LQT_THREAD, 'test' );
1567 - if ( ! $testTitle->userCan( 'create' ) ||
1568 - ! $testTitle->userCan( 'edit' ) )
1569 - {
1570 - return false;
 1559+ return self::canUserCreateThreads( $user );
 1560+ }
 1561+
 1562+ // Generally, not some specific page
 1563+ public static function canUserCreateThreads( $user ) {
 1564+ $userText = $user->getName();
 1565+
 1566+ static $canCreateNew = null;
 1567+ if ( !isset( $canCreateNew[$userText] ) ) {
 1568+ $title = Title::makeTitleSafe( NS_LQT_THREAD, 'Test title for LQT thread creation check' );
 1569+ $canCreateNew[$userText] = $title->userCan( 'create' ) && $title->userCan( 'edit' );
15711570 }
15721571
1573 - return true;
 1572+ return $canCreateNew[$userText];
15741573 }
15751574
15761575 public function signature() {

Follow-up revisions

RevisionCommit summaryAuthorDate
r80114Followup r80008: initialize $canCreateNew as an array, cause that's what it iscatrope20:24, 12 January 2011
r805261.17: MFT r78232, r78253, r79722, r79732, r79785, r79817, r79864, r79891, r79...catrope22:19, 18 January 2011

Status & tagging log