r1880 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r1879‎ | r1880 | r1881 >
Date:08:46, 4 November 2003
Author:vibber
Status:old
Tags:
Comment:
Backport use of memcached for linkcache individual lookups, with move fix
Modified paths:
  • /branches/stable/phase3/includes/LinkCache.php (modified) (history)
  • /branches/stable/phase3/includes/SpecialMovepage.php (modified) (history)

Diff [purge]

Index: branches/stable/phase3/includes/SpecialMovepage.php
@@ -338,7 +338,7 @@
339339
340340 function moveToNewTitle()
341341 {
342 - global $wgUser;
 342+ global $wgUser, $wgLinkCache;
343343 $fname = "MovePageForm::moveToNewTitle";
344344 $mt = wfMsg( "movedto" );
345345
@@ -348,6 +348,7 @@
349349 "cur_namespace={$this->nns},cur_title='{$this->ndt}' " .
350350 "WHERE cur_id={$this->oldid}";
351351 wfQuery( $sql, $fname );
 352+ $wgLinkCache->clearLink( $this->oft );
352353
353354 $common = "{$this->ons},'{$this->odt}'," .
354355 "'{$mt} \\\"{$this->nft}\\\"','" .
@@ -359,6 +360,7 @@
360361 "VALUES ({$common},'{$won}','{$now}','#REDIRECT [[{$this->nft}]]\n',1,1)";
361362 wfQuery( $sql, $fname );
362363 $this->newid = wfInsertId();
 364+ $wgLinkCache->clearLink( $this->nft );
363365
364366 $sql = "UPDATE old SET " .
365367 "old_namespace={$this->nns},old_title='{$this->ndt}' WHERE " .
Index: branches/stable/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;
@@ -67,7 +72,13 @@
6873 if ( isset( $index ) ) {
6974 unset( $this->mBadLinks[$index] );
7075 }
 76+ $this->clearLink( $title );
7177 }
 78+
 79+ function clearLink( $title ) {
 80+ global $wgMemc;
 81+ $wgMemc->delete( $this->getKey( $title ) );
 82+ }
7283
7384 function suspend() { $this->mActive = false; }
7485 function resume() { $this->mActive = true; }
@@ -92,22 +103,32 @@
93104 $id = $this->getGoodLinkID( $title );
94105 if ( 0 != $id ) { return $id; }
95106
96 - wfProfileIn( "LinkCache::addLink-checkdatabase" );
 107+ global $wgMemc;
 108+ $fname = "LinkCache::addLinkObj";
 109+ wfProfileIn( $fname );
97110
98111 $ns = $nt->getNamespace();
99112 $t = $nt->getDBkey();
100113
101 - if ( "" == $t ) { return 0; }
102 - $sql = "SELECT cur_id FROM cur WHERE cur_namespace=" .
103 - "{$ns} AND cur_title='" . wfStrencode( $t ) . "'";
104 - $res = wfQuery( $sql, "LinkCache::addLink" );
105 -
106 - if ( 0 == wfNumRows( $res ) ) {
107 - $id = 0;
108 - } else {
109 - $s = wfFetchObject( $res );
110 - $id = $s->cur_id;
 114+ if ( "" == $title ) {
 115+ wfProfileOut( $fname );
 116+ return 0;
111117 }
 118+
 119+ $id = $wgMemc->get( $key = $this->getKey( $title ) );
 120+ if( $id === FALSE ) {
 121+ $sql = "SELECT cur_id FROM cur WHERE cur_namespace=" .
 122+ "{$ns} AND cur_title='" . wfStrencode( $t ) . "'";
 123+ $res = wfQuery( $sql, $fname );
 124+
 125+ if ( 0 == wfNumRows( $res ) ) {
 126+ $id = 0;
 127+ } else {
 128+ $s = wfFetchObject( $res );
 129+ $id = $s->cur_id;
 130+ }
 131+ $wgMemc->add( $key, $id, time() + 3600 );
 132+ }
112133 if ( 0 == $id ) { $this->addBadLink( $title ); }
113134 else { $this->addGoodLink( $id, $title ); }
114135 wfProfileOut();
@@ -116,13 +137,14 @@
117138
118139 function preFill( $fromtitle )
119140 {
120 - wfProfileIn( "LinkCache::preFill" );
 141+ $fname = "LinkCache::preFill";
 142+ wfProfileIn( $fname );
121143 # Note -- $fromtitle is a Title *object*
122144 $dbkeyfrom = wfStrencode( $fromtitle->getPrefixedDBKey() );
123145 $sql = "SELECT cur_id,cur_namespace,cur_title
124146 FROM cur,links
125147 WHERE cur_id=l_to AND l_from='{$dbkeyfrom}'";
126 - $res = wfQuery( $sql, "LinkCache::preFill" );
 148+ $res = wfQuery( $sql, $fname );
127149 while( $s = wfFetchObject( $res ) ) {
128150 $this->addGoodLink( $s->cur_id,
129151 Title::makeName( $s->cur_namespace, $s->cur_title )

Status & tagging log