3 # Rebuild recent changes table.
5 function rebuildRecentChangesTable()
7 $sql = "DROP TABLE IF EXISTS recentchanges";
10 $sql = "CREATE TABLE recentchanges (
11 rc_timestamp varchar(14) binary NOT NULL default '',
12 rc_cur_time varchar(14) binary NOT NULL default '',
13 rc_user int(10) unsigned NOT NULL default '0',
14 rc_user_text varchar(255) binary NOT NULL default '',
15 rc_namespace tinyint(3) unsigned NOT NULL default '0',
16 rc_title varchar(255) binary NOT NULL default '',
17 rc_comment varchar(255) binary NOT NULL default '',
18 rc_minor tinyint(3) unsigned NOT NULL default '0',
19 rc_new tinyint(3) unsigned NOT NULL default '0',
20 rc_cur_id int(10) unsigned NOT NULL default '0',
21 rc_this_oldid int(10) unsigned NOT NULL default '0',
22 rc_last_oldid int(10) unsigned NOT NULL default '0',
23 INDEX rc_cur_id (rc_cur_id),
24 INDEX rc_cur_time (rc_cur_time),
25 INDEX rc_timestamp (rc_timestamp),
26 INDEX rc_namespace (rc_namespace),
27 INDEX rc_title (rc_title)
28 ) TYPE=MyISAM PACK_KEYS=1;";
31 print( "Loading from CUR table...\n" );
33 $sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time,rc_user," .
34 "rc_user_text,rc_namespace,rc_title,rc_comment,rc_minor,rc_new," .
35 "rc_cur_id,rc_this_oldid,rc_last_oldid) SELECT cur_timestamp," .
36 "cur_timestamp,cur_user,cur_user_text,cur_namespace,cur_title," .
37 "cur_comment,cur_minor_edit,cur_is_new,cur_id,0,0 FROM cur " .
38 "ORDER BY cur_timestamp DESC LIMIT 5000";
41 print( "Loading from OLD table...\n" );
43 $sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time,rc_user," .
44 "rc_user_text,rc_namespace,rc_title,rc_comment,rc_minor,rc_new," .
45 "rc_cur_id,rc_this_oldid,rc_last_oldid) SELECT old_timestamp,''," .
46 "old_user,old_user_text,old_namespace,old_title,old_comment," .
47 "old_minor_edit,0,0,old_id,0 FROM old ORDER BY old_timestamp " .
51 $sql = "SELECT rc_timestamp FROM recentchanges " .
52 "ORDER BY rc_timestamp DESC LIMIT 5000,1";
53 $res = wfQuery( $sql );
54 $obj = wfFetchObject( $res );
55 $ts = $obj->rc_timestamp;
57 $sql = "DELETE FROM recentchanges WHERE rc_timestamp < '{$ts}'";
60 rebuildRecentChangesTablePass2();
63 function rebuildRecentChangesTablePass2()
65 $ns = $id = $count = 0;
68 print( "Updating links...\n" );
70 $sql = "SELECT rc_namespace,rc_title,rc_timestamp FROM recentchanges " .
71 "ORDER BY rc_namespace,rc_title,rc_timestamp DESC";
72 $res = wfQuery( $sql );
74 while ( $obj = wfFetchObject( $res ) ) {
75 if ( ! ( $ns == $obj->rc_namespace &&
76 0 == strcmp( $title, wfStrencode( $obj->rc_title ) ) ) ) {
78 $ns = $obj->rc_namespace;
79 $title = wfStrencode( $obj->rc_title );
81 $sql = "SELECT cur_id,cur_timestamp FROM cur WHERE " .
82 "cur_namespace={$ns} AND cur_title='{$title}'";
83 $res2 = wfQuery( $sql );
84 $obj2 = wfFetchObject( $res2 );
87 $ct = $obj2->cur_timestamp;
89 $sql = "SELECT old_id FROM old WHERE old_namespace={$ns} " .
90 "AND old_title='{$title}' AND old_timestamp < '" .
91 "{$obj->rc_timestamp}' ORDER BY old_timestamp DESC LIMIT 1";
92 $res2 = wfQuery( $sql );
94 if ( 0 != wfNumRows( $res2 ) ) {
95 $obj2 = wfFetchObject( $res2 );
97 $sql = "UPDATE recentchanges SET rc_cur_id={$id},rc_cur_time=" .
98 "'{$ct}',rc_last_oldid={$obj2->old_id} WHERE " .
99 "rc_namespace={$ns} AND rc_title='{$title}' AND " .
100 "rc_timestamp='{$obj->rc_timestamp}'";
103 $sql = "UPDATE recentchanges SET rc_cur_id={$id},rc_cur_time=" .
104 "'{$ct}' WHERE rc_namespace={$ns} AND rc_title='{$title}' " .
105 "AND rc_timestamp='{$obj->rc_timestamp}'";
109 if ( 0 == ( ++$count % 500 ) ) {
110 printf( "%d records processed.\n", $count );