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->timestamp( $cutoff ),
42 ), $fname, array( 'ORDER BY' => 'rev_timestamp', 'LIMIT' => 5000 )
46 function rebuildRecentChangesTablePass2()
48 $dbw =& wfGetDB( DB_MASTER );
49 extract( $dbw->tableNames( 'recentchanges', 'revision' ) );
51 $ns = $id = $count = 0;
54 print( "Updating links...\n" );
56 # Fill in the rc_last_oldid field, which points to the previous edit
58 $sql = "SELECT rc_cur_id,rc_this_oldid,rc_timestamp FROM $recentchanges " .
59 "ORDER BY rc_cur_id,rc_timestamp";
60 $res = $dbw->query( $sql, DB_MASTER );
64 while ( $obj = $dbw->fetchObject( $res ) ) {
66 if( $obj->rc_cur_id != $lastCurId ) {
67 # Switch! Look up the previous last edit, if any
68 $lastCurId = intval( $obj->rc_cur_id );
69 $emit = $obj->rc_timestamp;
70 $sql2 = "SELECT rev_id FROM $revision " .
71 "WHERE rev_page={$lastCurId} ".
72 "AND rev_timestamp<'{$emit}' ORDER BY rev_timestamp DESC LIMIT 1";
73 $res2 = $dbw->query( $sql2 );
74 if( $row = $dbw->fetchObject( $res2 ) ) {
75 $lastOldId = intval( $row->rev_id );
81 $dbw->freeResult( $res2 );
83 if( $lastCurId == 0 ) {
84 print "Uhhh, something wrong? No curid\n";
86 $sql3 = "UPDATE $recentchanges SET rc_last_oldid=$lastOldId,rc_new=$new,rc_type=$new " .
87 "WHERE rc_cur_id={$lastCurId} AND rc_this_oldid={$obj->rc_this_oldid}";
89 $lastOldId = intval( $obj->rc_this_oldid );
92 $dbw->freeResult( $res );