This saves trouble in a number of places where we can now do joins with the link tables to get other info (such as cur_is_redirect!) as well as the name, and fewer bits need to be juggled on page renaming, as outgoing links no longer have to be changed (cur_id remains the same when a page is renamed). rebuildLinks.inc and some of the tools in the 'maintenance page' still need to be updated to work with the new setup. (Special:Maintenance needs a *lot* of cleanup in general. It's kind of a catch-all of vaguely defined features which suck performance like a hydroelectric dam.) Also I've slipped in some extra debug code. And, I think 'indexes.sql' is a big waste of time and should all be moved into tables.sql. Building indexes separately doesn't help on InnoDB and won't do anything on MyISAM either if you're just going to replace the table after it's built with an imported one from a dump which creates it with indexes.
70 lines
2 KiB
PHP
70 lines
2 KiB
PHP
<?php
|
|
|
|
class ParserCache
|
|
{
|
|
function get( &$article, &$user ){
|
|
$hash = $user->getPageRenderingHash();
|
|
$pageid = intval( $id );
|
|
$res = wfQuery("SELECT pc_data FROM parsercache WHERE pc_pageid = {$pageid} ".
|
|
" AND pc_prefhash = '{$hash}' AND pc_expire > NOW()", DB_WRITE);
|
|
$row = wfFetchObject ( $res );
|
|
if( $row ){
|
|
$retVal = unserialize( gzuncompress($row->pc_data) );
|
|
wfProfileOut( $fname );
|
|
} else {
|
|
$retVal = false;
|
|
}
|
|
return $retVal;
|
|
}
|
|
|
|
function save( $parserOutput, &$article, &$user ){
|
|
$hash = $user->getPageRenderingHash();
|
|
$pageid = intval( $article->getID() );
|
|
$title = wfStrencode( $article->mTitle->getPrefixedDBKey() );
|
|
$ser = addslashes( gzcompress( serialize( $parserOutput ) ) );
|
|
if( $parserOutput->containsOldMagic() ){
|
|
$expire = "1 HOUR";
|
|
} else {
|
|
$expire = "7 DAY";
|
|
}
|
|
|
|
wfQuery("REPLACE INTO parsercache (pc_prefhash,pc_pageid,pc_title,pc_data, pc_expire) ".
|
|
"VALUES('{$hash}', {$pageid}, '{$title}', '{$ser}', ".
|
|
"DATE_ADD(NOW(), INTERVAL {$expire}))", DB_WRITE);
|
|
|
|
if( rand() % 50 == 0 ){ // more efficient to just do it sometimes
|
|
$this->purge();
|
|
}
|
|
}
|
|
|
|
function purge(){
|
|
wfQuery("DELETE FROM parsercache WHERE pc_expire < NOW() LIMIT 250", DB_WRITE);
|
|
}
|
|
|
|
function clearLinksTo( $pid ){
|
|
$pid = intval( $pid );
|
|
wfQuery("DELETE parsercache FROM parsercache,links ".
|
|
"WHERE pc_pageid=links.l_from AND l_to={$pid}", DB_WRITE);
|
|
wfQuery("DELETE FROM parsercache WHERE pc_pageid='{$pid}'", DB_WRITE);
|
|
}
|
|
|
|
# $title is a prefixed db title, for example like Title->getPrefixedDBkey() returns.
|
|
function clearBrokenLinksTo( $title ){
|
|
$title = wfStrencode( $title );
|
|
wfQuery("DELETE parsercache FROM parsercache,brokenlinks ".
|
|
"WHERE pc_pageid=bl_from AND bl_to='{$title}'", DB_WRITE);
|
|
}
|
|
|
|
# $pid is a page id
|
|
function clearPage( $pid, $namespace ){
|
|
$pid = intval( $pid );
|
|
if( $namespace == NS_MEDIAWIKI ){
|
|
$this->clearLinksTo( $pid );
|
|
} else {
|
|
wfQuery("DELETE FROM parsercache WHERE pc_pageid='{$pid}'", DB_WRITE);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
?>
|