*Try to use rev_len first to avoid hitting text table as much
authorAaron Schulz <aaron@users.mediawiki.org>
Wed, 6 Jun 2007 04:38:10 +0000 (04:38 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Wed, 6 Jun 2007 04:38:10 +0000 (04:38 +0000)
maintenance/rebuildrecentchanges.inc

index 03cffa1..dab8614 100644 (file)
@@ -64,16 +64,19 @@ function rebuildRecentChangesTablePass2()
                        # Switch! Look up the previous last edit, if any
                        $lastCurId = intval( $obj->rc_cur_id );
                        $emit = $obj->rc_timestamp;
-                       $sql2 = "SELECT rev_id, rev_text_id FROM $revision " .
+                       $sql2 = "SELECT rev_id, rev_len, rev_text_id FROM $revision " .
                                "WHERE rev_page={$lastCurId} ".
                                "AND rev_timestamp<'{$emit}' ORDER BY rev_timestamp DESC LIMIT 1";
                        $res2 = $dbw->query( $sql2 );
                        if( $row = $dbw->fetchObject( $res2 ) ) {
                                $lastOldId = intval( $row->rev_id );
                                $lastTextId = intval( $row->rev_text_id );
+                               $lastSize = $row->rev_len; # Grab the last text size
                        } else {
                                # No previous edit
-                               $lastOldId = $lastTextId = 0;
+                               $lastOldId = 0;
+                               $lastTextId = 0;
+                               $lastSize = NULL;
                                $new = 1;
                        }
                        $dbw->freeResult( $res2 );
@@ -81,18 +84,31 @@ function rebuildRecentChangesTablePass2()
                if( $lastCurId == 0 ) {
                        print "Uhhh, something wrong? No curid\n";
                } else {
-                       # Grab the last edit's text size
-                       $lastText = $dbw->selectField( 'text', 'old_text', array('old_id' => $lastTextId ) );
-                       $lastSize = $lastText ? strlen($lastText) : 'NULL';
+                       # Check the text if not in rev_len for the last entry's text size
+                       if( !$lastSize ) {
+                               $lastText = $dbw->selectField( 'text', 'old_text', array('old_id' => $lastTextId ) );
+                               $lastSize = $lastText ? strlen($lastText) : 'NULL';
+                       }
                        # Grab the entry's text size
-                       $textId = $dbw->selectField( 'revision', 'rev_text_id', array('rev_id' => $obj->rc_this_oldid ) );
-                       $text = $dbw->selectField( 'text', 'old_text', array('old_id' => $textId ) );
-                       $size = $text ? strlen($text) : 'NULL';
+                       $res3 = $dbw->select( 'revision', array('rev_len','rev_text_id'), array('rev_id' => $obj->rc_this_oldid ) );
+                       if( $row = $dbw->fetchObject( $res3 ) ) {
+                               $textId = $row->rev_text_id;
+                               $size = $row->rev_len;
+                       } else {
+                               $textId = 0;
+                               $size = NULL;
+                       }
+                       # Check the text if not in rev_len for the entry's text size
+                       if( !$size ) {
+                               $text = $dbw->selectField( 'text', 'old_text', array('old_id' => $textId ) );
+                               $size = $text ? strlen($text) : 'NULL';
+                       }
                        
                        $sql3 = "UPDATE $recentchanges SET rc_last_oldid=$lastOldId,rc_new=$new,rc_type=$new," .
-                               "rc_old_len=$lastSize,rc_new_len=$size " .
+                               "rc_old_len='$lastSize',rc_new_len='$size' " .
                                "WHERE rc_cur_id={$lastCurId} AND rc_this_oldid={$obj->rc_this_oldid}";
                        $dbw->query( $sql3 );
+                       
                        $lastOldId = intval( $obj->rc_this_oldid );
                }
        }