3 * Rebuild recent changes table.
7 * @subpackage Maintenance
11 function rebuildRecentChangesTablePass1()
13 $fname = 'rebuildRecentChangesTablePass1';
14 $dbw =& wfGetDB( DB_MASTER );
15 extract( $dbw->tableNames( 'recentchanges', 'cur', 'old' ) );
17 $dbw->delete( 'recentchanges', '*' );
19 print( "Loading from page and revision tables...\n" );
22 $cutoff = time() - $wgRCMaxAge;
23 $dbw->insertSelect( 'recentchanges', array( 'page', 'revision' ),
25 'rc_timestamp' => 'rev_timestamp',
26 'rc_cur_time' => 'rev_timestamp',
27 'rc_user' => 'rev_user',
28 'rc_user_text' => 'rev_user_text',
29 'rc_namespace' => 'page_namespace',
30 'rc_title' => 'page_title',
31 'rc_comment' => 'rev_comment',
32 'rc_minor' => 'rev_minor_edit',
34 'rc_new' => 'page_is_new',
35 'rc_cur_id' => 'page_id',
36 'rc_this_oldid' => 'rev_id',
37 'rc_last_oldid' => 0, // is this ok?
38 'rc_type' => $dbw->conditional( 'page_is_new != 0', RC_NEW, RC_EDIT ),
40 'rev_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $cutoff ) ),
43 array(), // INSERT options
44 array( 'ORDER BY' => 'rev_timestamp', 'LIMIT' => 5000 ) // SELECT options
48 function rebuildRecentChangesTablePass2()
50 $dbw =& wfGetDB( DB_MASTER );
51 extract( $dbw->tableNames( 'recentchanges', 'revision' ) );
53 $ns = $id = $count = 0;
56 print( "Updating links...\n" );
58 # Fill in the rc_last_oldid field, which points to the previous edit
60 $sql = "SELECT rc_cur_id,rc_this_oldid,rc_timestamp FROM $recentchanges " .
61 "ORDER BY rc_cur_id,rc_timestamp";
62 $res = $dbw->query( $sql, DB_MASTER );
66 while ( $obj = $dbw->fetchObject( $res ) ) {
68 if( $obj->rc_cur_id != $lastCurId ) {
69 # Switch! Look up the previous last edit, if any
70 $lastCurId = intval( $obj->rc_cur_id );
71 $emit = $obj->rc_timestamp;
72 $sql2 = "SELECT rev_id FROM $revision " .
73 "WHERE rev_page={$lastCurId} ".
74 "AND rev_timestamp<'{$emit}' ORDER BY rev_timestamp DESC LIMIT 1";
75 $res2 = $dbw->query( $sql2 );
76 if( $row = $dbw->fetchObject( $res2 ) ) {
77 $lastOldId = intval( $row->rev_id );
83 $dbw->freeResult( $res2 );
85 if( $lastCurId == 0 ) {
86 print "Uhhh, something wrong? No curid\n";
88 $sql3 = "UPDATE $recentchanges SET rc_last_oldid=$lastOldId,rc_new=$new,rc_type=$new " .
89 "WHERE rc_cur_id={$lastCurId} AND rc_this_oldid={$obj->rc_this_oldid}";
91 $lastOldId = intval( $obj->rc_this_oldid );
94 $dbw->freeResult( $res );