r39974 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r39973‎ | r39974 | r39975 >
Date:21:24, 25 August 2008
Author:aaron
Status:old
Tags:
Comment:
* Add nice doSaveCompression() function to avoid duplication
* Don't store text when not needed
* Don't expand text when not needed
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevision.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.class.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/specialpages/RevisionReview_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
@@ -1034,36 +1034,20 @@
10351035 }
10361036 }
10371037
1038 - # Set our versioning params cache
1039 - self::setIncludeVersionCache( $rev->getId(), $poutput->mTemplateIds, $poutput->fr_ImageSHA1Keys );
1040 - # Get the page text and resolve all templates
1041 - list($fulltext,$templateIDs,$complete,$maxID) = self::expandText( $text, $article->getTitle(), $rev->getId() );
1042 - # Clear our versioning params cache
1043 - self::clearIncludeVersionCache( $rev->getId() );
1044 -
1045 - # Compress $fulltext, passed by reference
1046 - $textFlags = FlaggedRevision::compressText( $fulltext );
1047 -
1048 - # Write to external storage if required
1049 - $storage = self::getExternalStorage();
1050 - if( $storage ) {
1051 - if( is_array($storage) ) {
1052 - # Distribute storage across multiple clusters
1053 - $store = $storage[mt_rand(0, count( $storage ) - 1)];
1054 - } else {
1055 - $store = $storage;
1056 - }
1057 - # Store and get the URL
1058 - $fulltext = ExternalStore::insert( $store, $fulltext );
1059 - if( !$fulltext ) {
1060 - # This should only happen in the case of a configuration error, where the external store is not valid
1061 - wfProfileOut( __METHOD__ );
1062 - throw new MWException( "Unable to store text to external storage $store" );
1063 - }
1064 - if( $textFlags ) {
1065 - $textFlags .= ',';
1066 - }
1067 - $textFlags .= 'external';
 1038+ global $wgUseStableTemplates;
 1039+ if( $wgUseStableTemplates ) {
 1040+ $fulltext = '';
 1041+ $textFlags = 'dynamic';
 1042+ } else {
 1043+ # Set our versioning params cache
 1044+ self::setIncludeVersionCache( $rev->getId(), $poutput->mTemplateIds, $poutput->fr_ImageSHA1Keys );
 1045+ # Get the page text and resolve all templates
 1046+ list($fulltext,$templateIDs,$complete,$maxID) = self::expandText( $text,
 1047+ $article->getTitle(), $rev->getId() );
 1048+ # Clear our versioning params cache
 1049+ self::clearIncludeVersionCache( $rev->getId() );
 1050+ # Store/compress text as needed, and get the flags
 1051+ $textFlags = FlaggedRevision::doSaveCompression( $fulltext );
10681052 }
10691053
10701054 # If this is an image page, store corresponding file info
Index: trunk/extensions/FlaggedRevs/FlaggedRevision.php
@@ -363,6 +363,10 @@
364364 $this->mFlags = explode(',',$row->fr_flags);
365365 }
366366 }
 367+ // Should the text actually be made dynamically?
 368+ if( in_array( 'dynamic', $this->mFlags ) ) {
 369+ return $this->getRevText();
 370+ }
367371 // Check if fr_text is just some URL to external DB storage
368372 if( in_array( 'external', $this->mFlags ) ) {
369373 $url = $this->mRawDBText;
@@ -385,7 +389,47 @@
386390 return true;
387391 }
388392
389 - /**
 393+ /**
 394+ * @param string $fulltext
 395+ * @return string, flags
 396+ * Compress pre-processed text, passed by reference
 397+ * Accounts for various config options.
 398+ */
 399+ public static function doSaveCompression( &$fulltext ) {
 400+ # Flag items that do not have text stored
 401+ global $wgUseStableTemplates;
 402+ if( $wgUseStableTemplates ) {
 403+ $fulltext = '';
 404+ $textFlags = 'dynamic';
 405+ } else {
 406+ # Compress $fulltext, passed by reference
 407+ $textFlags = self::compressText( $fulltext );
 408+ # Write to external storage if required
 409+ $storage = FlaggedRevs::getExternalStorage();
 410+ if( $storage ) {
 411+ if( is_array($storage) ) {
 412+ # Distribute storage across multiple clusters
 413+ $store = $storage[mt_rand(0, count( $storage ) - 1)];
 414+ } else {
 415+ $store = $storage;
 416+ }
 417+ # Store and get the URL
 418+ $fulltext = ExternalStore::insert( $store, $fulltext );
 419+ if( !$fulltext ) {
 420+ # This should only happen in the case of a configuration error, where the external store is not valid
 421+ wfProfileOut( __METHOD__ );
 422+ throw new MWException( "Unable to store text to external storage $store" );
 423+ }
 424+ if( $textFlags ) {
 425+ $textFlags .= ',';
 426+ }
 427+ $textFlags .= 'external';
 428+ }
 429+ }
 430+ return $textFlags;
 431+ }
 432+
 433+ /**
390434 * @param string $text
391435 * @return string, flags
392436 * Compress pre-processed text, passed by reference
Index: trunk/extensions/FlaggedRevs/specialpages/RevisionReview_body.php
@@ -627,33 +627,11 @@
628628 wfProfileOut( __METHOD__ );
629629 return true;
630630 }
631 - }
632 -
633 - # Compress $fulltext, passed by reference
634 - $textFlags = FlaggedRevision::compressText( $fulltext );
635 -
636 - # Write to external storage if required
637 - $storage = FlaggedRevs::getExternalStorage();
638 - if( $storage ) {
639 - if( is_array($storage) ) {
640 - # Distribute storage across multiple clusters
641 - $store = $storage[mt_rand(0, count( $storage ) - 1)];
642 - } else {
643 - $store = $storage;
644 - }
645 - # Store and get the URL
646 - $fulltext = ExternalStore::insert( $store, $fulltext );
647 - if( !$fulltext ) {
648 - # This should only happen in the case of a configuration error, where the external store is not valid
649 - wfProfileOut( __METHOD__ );
650 - throw new MWException( "Unable to store text to external storage $store" );
651 - }
652 - if( $textFlags ) {
653 - $textFlags .= ',';
654 - }
655 - $textFlags .= 'external';
656631 }
657632
 633+ # Store/compress text as needed, and get the flags
 634+ $textFlags = FlaggedRevision::doSaveCompression( $fulltext );
 635+
658636 $dbw = wfGetDB( DB_MASTER );
659637 # Our review entry
660638 $revset = array(

Status & tagging log