r1882 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r1881‎ | r1882 | r1883 >
Date:08:59, 4 November 2003
Author:vibber
Status:old
Tags:
Comment:
Fix move page / linkcache / memcached problem
Modified paths:
  • /trunk/phase3/includes/LinkCache.php (modified) (history)
  • /trunk/phase3/includes/SpecialMovepage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialMovepage.php
@@ -261,7 +261,7 @@
262262
263263 function moveOverExistingRedirect()
264264 {
265 - global $wgUser;
 265+ global $wgUser, $wgLinkCache;
266266 $fname = "MovePageForm::moveOverExistingRedirect";
267267 $mt = wfMsg( "movedto" );
268268
@@ -270,6 +270,7 @@
271271 "cur_namespace={$this->nns},cur_title='{$this->ndt}' " .
272272 "WHERE cur_id={$this->oldid}";
273273 wfQuery( $sql, DB_WRITE, $fname );
 274+ $wgLinkCache->clearLink( $this->nft );
274275
275276 $sql = "UPDATE cur SET cur_touched='{$now}'," .
276277 "cur_namespace={$this->ons},cur_title='{$this->odt}'," .
@@ -279,6 +280,7 @@
280281 "cur_user_text='" . wfStrencode( $wgUser->getName() ) . "'," .
281282 "cur_is_redirect=1,cur_is_new=0 WHERE cur_id={$this->newid}";
282283 wfQuery( $sql, DB_WRITE, $fname );
 284+ $wgLinkCache->clearLink( $this->oft );
283285
284286 $sql = "UPDATE old SET " .
285287 "old_namespace={$this->nns},old_title='{$this->ndt}' WHERE " .
@@ -332,7 +334,7 @@
333335
334336 function moveToNewTitle()
335337 {
336 - global $wgUser;
 338+ global $wgUser, $wgLinkCache;
337339 $fname = "MovePageForm::moveToNewTitle";
338340 $mt = wfMsg( "movedto" );
339341
@@ -342,6 +344,7 @@
343345 "cur_namespace={$this->nns},cur_title='{$this->ndt}' " .
344346 "WHERE cur_id={$this->oldid}";
345347 wfQuery( $sql, DB_WRITE, $fname );
 348+ $wgLinkCache->clearLink( $this->nft );
346349
347350 $common = "{$this->ons},'{$this->odt}'," .
348351 "'{$mt} \\\"{$this->nft}\\\"','" .
@@ -353,6 +356,7 @@
354357 "VALUES ({$common},'{$won}','{$now}','#REDIRECT [[{$this->nft}]]\n',1,1)";
355358 wfQuery( $sql, DB_WRITE, $fname );
356359 $this->newid = wfInsertId();
 360+ $wgLinkCache->clearLink( $this->oft );
357361
358362 $sql = "UPDATE old SET " .
359363 "old_namespace={$this->nns},old_title='{$this->ndt}' WHERE " .
Index: trunk/phase3/includes/LinkCache.php
@@ -12,6 +12,11 @@
1313 /* private */ var $mImageLinks;
1414 /* private */ var $mPreFilled, $mOldGoodLinks, $mOldBadLinks;
1515
 16+ /* private */ function getKey( $title ) {
 17+ global $wgDBname;
 18+ return "$wgDBname:lc:title:$title";
 19+ }
 20+
1621 function LinkCache()
1722 {
1823 $this->mActive = true;
@@ -56,15 +61,24 @@
5762 if ( $this->mActive ) { $this->mImageLinks[$title] = 1; }
5863 }
5964
 65+ function addImageLinkObj( $nt )
 66+ {
 67+ if ( $this->mActive ) { $this->mImageLinks[$nt->getDBkey()] = 1; }
 68+ }
 69+
6070 function clearBadLink( $title )
6171 {
6272 $index = array_search( $title, $this->mBadLinks );
6373 if ( isset( $index ) ) {
6474 unset( $this->mBadLinks[$index] );
6575 }
66 - global $wgMemc, $wgDBname;
67 - $wgMemc->delete( "$wgDBname:lc:title:$title" );
 76+ $this->clearLink( $title );
6877 }
 78+
 79+ function clearLink( $title ) {
 80+ global $wgMemc;
 81+ $wgMemc->delete( $this->getKey( $title ) );
 82+ }
6983
7084 function suspend() { $this->mActive = false; }
7185 function resume() { $this->mActive = true; }
@@ -74,31 +88,37 @@
7589
7690 function addLink( $title )
7791 {
78 - return $this->addLinkObj( Title::newFromDBkey( $title ) );
 92+ $nt = Title::newFromDBkey( $title );
 93+ if( $nt ) {
 94+ return $this->addLinkObj( $nt );
 95+ } else {
 96+ return 0;
 97+ }
7998 }
8099
81100 function addLinkObj( &$nt )
82101 {
83 - $title = $nt->getDBkey();
 102+ $title = $nt->getPrefixedDBkey();
84103 if ( $this->isBadLink( $title ) ) { return 0; }
85104 $id = $this->getGoodLinkID( $title );
86105 if ( 0 != $id ) { return $id; }
87106
88 - global $wgMemc, $wgDBname;
89 - $fname = "LinkCache::addLink-checkdatabase";
 107+ global $wgMemc;
 108+ $fname = "LinkCache::addLinkObj";
90109 wfProfileIn( $fname );
91110
92111 $ns = $nt->getNamespace();
 112+ $t = $nt->getDBkey();
93113
94114 if ( "" == $title ) {
95115 wfProfileOut( $fname );
96116 return 0;
97117 }
98118
99 - $id = $wgMemc->get( $key = "$wgDBname:lc:title:$title" );
 119+ $id = $wgMemc->get( $key = $this->getKey( $title ) );
100120 if( $id === FALSE ) {
101 - $sql = "SELECT HIGH_PRIORITY cur_id FROM cur WHERE cur_namespace=" .
102 - "{$ns} AND cur_title='" . wfStrencode( $title ) . "'";
 121+ $sql = "SELECT cur_id FROM cur WHERE cur_namespace=" .
 122+ "{$ns} AND cur_title='" . wfStrencode( $t ) . "'";
103123 $res = wfQuery( $sql, DB_READ, "LinkCache::addLink" );
104124
105125 if ( 0 == wfNumRows( $res ) ) {
@@ -121,10 +141,10 @@
122142 wfProfileIn( $fname );
123143 # Note -- $fromtitle is a Title *object*
124144 $dbkeyfrom = wfStrencode( $fromtitle->getPrefixedDBKey() );
125 - $sql = "SELECT HIGH_PRIORITY cur_id,cur_namespace,cur_title
 145+ $sql = "SELECT cur_id,cur_namespace,cur_title
126146 FROM cur,links
127147 WHERE cur_id=l_to AND l_from='{$dbkeyfrom}'";
128 - $res = wfQuery( $sql, DB_READ, "LinkCache::preFill" );
 148+ $res = wfQuery( $sql, DB_READ, $fname );
129149 while( $s = wfFetchObject( $res ) ) {
130150 $this->addGoodLink( $s->cur_id,
131151 Title::makeName( $s->cur_namespace, $s->cur_title )
@@ -135,7 +155,7 @@
136156 $id = $fromtitle->getArticleID();
137157 $this->resume();
138158
139 - $sql = "SELECT HIGH_PRIORITY bl_to
 159+ $sql = "SELECT bl_to
140160 FROM brokenlinks
141161 WHERE bl_from='{$id}'";
142162 $res = wfQuery( $sql, DB_READ, "LinkCache::preFill" );

Status & tagging log