r56706 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56705‎ | r56706 | r56707 >
Date:14:50, 21 September 2009
Author:werdna
Status:deferred
Tags:
Comment:
LiquidThreads:
* Use user signature, instead of userLink + userToolLinks as the signature for a thread.
* Drop automatic leading — -- users can add it to their signatures if they want it.
* Includes caching infrastructure for pre-caching signatures on thread bulk-load, to prevent a zillion queries.
Modified paths:
  • /trunk/extensions/LiquidThreads/classes/Thread.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/View.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/classes/View.php
@@ -27,6 +27,8 @@
2828 protected $sort_order = LQT_NEWEST_CHANGES;
2929
3030 static $stylesAndScriptsDone = false;
 31+
 32+ static $userSignatureCache = array();
3133
3234 function __construct( &$output, &$article, &$title, &$user, &$request ) {
3335 $this->article = $article;
@@ -826,11 +828,8 @@
827829 $sk = $wgUser->getSkin();
828830
829831 $author = $thread->author();
830 - $signature = $sk->userLink( $author->getId(), $author->getName() );
831 - $signature = '— '. Xml::tags( 'span', array( 'class' => 'lqt-thread-author' ),
832 - $signature );
833 - $signature .= $sk->userToolLinks( $author->getId(), $author->getName() );
834832
 833+ $signature = $this->getSignature( $author );
835834 $signature = Xml::tags( 'div', array( 'class' => 'lqt-thread-signature' ),
836835 $signature );
837836
@@ -1194,4 +1193,33 @@
11951194 function showSummary( $t ) {
11961195 $this->output->addHTML( $this->getSummary( $t ) );
11971196 }
 1197+
 1198+ function getSignature( $user ) {
 1199+ if ( is_object($user) ) {
 1200+ $uid = $user->getId();
 1201+ } elseif ( is_integer($user) ) {
 1202+ $uid = $user;
 1203+ $user = null;
 1204+ } else {
 1205+ $user = User::newFromName( $user );
 1206+ $uid = $user->getId();
 1207+ }
 1208+
 1209+ if ( isset( self::$userSignatureCache[$uid] ) ) {
 1210+ return self::$userSignatureCache[$uid];
 1211+ }
 1212+
 1213+ if (!$user) {
 1214+ $user = User::newFromId( $uid );
 1215+ }
 1216+
 1217+ global $wgParser, $wgOut;
 1218+
 1219+ $sig = $wgParser->getUserSig( $user );
 1220+ $sig = $wgOut->parseInline( $sig );
 1221+
 1222+ self::$userSignatureCache[$uid] = $sig;
 1223+
 1224+ return $sig;
 1225+ }
11981226 }
Index: trunk/extensions/LiquidThreads/classes/Thread.php
@@ -364,6 +364,7 @@
365365 $all_thread_rows = $rows;
366366 $pageIds = array();
367367 $linkBatch = new LinkBatch();
 368+ $userIds = array();
368369
369370 if (!is_array(self::$replyCacheById)) {
370371 self::$replyCacheById = array();
@@ -460,12 +461,52 @@
461462 $linkBatch->addObj( $t );
462463
463464 User::$idCacheByName[$row->thread_author_name] = $row->thread_author_id;
 465+ $userIds[$row->thread_author_id] = true;
464466
465467 if ( $row->thread_parent ) {
466468 self::$replyCacheById[$row->thread_parent][$row->thread_id] = $thread;
467469 }
468470 }
469471
 472+ $userIds = array_keys($userIds);
 473+
 474+ // Pull signature data and pre-cache in View object.
 475+ if ( count($userIds) ) {
 476+ $signatureDataCache = array_fill_keys( $userIds, array() );
 477+ $res = $dbr->select( 'user_properties',
 478+ array( 'up_user', 'up_property', 'up_value' ),
 479+ array( 'up_property' => array('nickname', 'fancysig'),
 480+ 'up_user' => $userIds ),
 481+ __METHOD__ );
 482+
 483+ foreach( $res as $row ) {
 484+ $signatureDataCache[$row->up_user][$row->up_property] = $row->up_value;
 485+ }
 486+
 487+ global $wgParser, $wgOut;
 488+
 489+ foreach( $userIds as $uid ) {
 490+ $user = User::newFromId($uid); // Should pull from UID cache.
 491+
 492+ // Grab sig data
 493+ $nickname = null;
 494+ $fancysig = (bool)User::getDefaultOption( 'fancysig' );
 495+
 496+ if ( isset($signatureDataCache[$uid]['nickname']) )
 497+ $nickname = $signatureDataCache[$uid]['nickname'];
 498+ if( isset($signatureDataCache[$uid]['fancysig']) )
 499+ $fancysig = $signatureDataCache[$uid]['fancysig'];
 500+
 501+ // Generate signature from Parser
 502+
 503+ $sig = $wgParser->getUserSig( $user, $nickname, $fancysig );
 504+ $sig = $wgOut->parseInline( $sig );
 505+
 506+ // Save into LqtView for later use.
 507+ LqtView::$userSignatureCache[$uid] = $sig;
 508+ }
 509+ }
 510+
470511 // Pull link batch data.
471512 $linkBatch->execute();
472513

Follow-up revisions

RevisionCommit summaryAuthorDate
r57097Add signature prefetching logic to Parser, supports r56706.werdna10:35, 30 September 2009

Status & tagging log