r1878 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r1877‎ | r1878 | r1879 >
Date:03:59, 4 November 2003
Author:vibber
Status:old
Tags:
Comment:
Backport memcached use in linkcache, plus some experimental enhancements for precaching
Modified paths:
  • /branches/stable/phase3/includes/Article.php (modified) (history)
  • /branches/stable/phase3/includes/DefaultSettings.php (modified) (history)
  • /branches/stable/phase3/includes/LinkCache.php (modified) (history)
  • /branches/stable/phase3/includes/LinksUpdate.php (modified) (history)

Diff [purge]

Index: branches/stable/phase3/includes/Article.php
@@ -679,7 +679,7 @@
680680 wfStrencode( $summary ) . "',0,0," .
681681 ( $wgUser->isBot() ? 1 : 0 ) . ")";
682682 wfQuery( $sql, $fname );
683 - if ($watchthis) {
 683+ if ($watchthis) {
684684 if(!$wgTitle->userIsWatching()) $this->watch();
685685 } else {
686686 if ( $wgTitle->userIsWatching() ) {
@@ -1335,8 +1335,10 @@
13361336 $now = wfTimestampNow();
13371337 $sql2 = "UPDATE cur SET cur_touched='{$now}' WHERE cur_id IN (";
13381338 $first = true;
1339 -
 1339+
 1340+ global $wgLinkCache;
13401341 while ( $s = wfFetchObject( $res ) ) {
 1342+ $wgLinkCache->clearPreFill( $s->l_from );
13411343 $nt = Title::newFromDBkey( $s->l_from );
13421344 $lid = $nt->getArticleID();
13431345
@@ -1363,6 +1365,9 @@
13641366
13651367 $sql = "DELETE FROM brokenlinks WHERE bl_from={$id}";
13661368 wfQuery( $sql, $fname );
 1369+
 1370+ global $wgLinkCache;
 1371+ $wgLinkCache->clearPreFill( $t );
13671372 }
13681373
13691374 $log = new LogPage( wfMsg( "dellogpage" ), wfMsg( "dellogpagetext" ) );
Index: branches/stable/phase3/includes/DefaultSettings.php
@@ -37,6 +37,13 @@
3838 $wgDBtransactions = false; # Set to true if using InnoDB tables
3939 $wgDBmysql4 = false; # Set to true to use enhanced fulltext search
4040
 41+# memcached settings
 42+# See docs/memcached.doc
 43+#
 44+$wgUseMemCached = false;
 45+$wgMemCachedServers = array( "127.0.0.1:11000" );
 46+$wgMemCachedDebug = false;
 47+
4148 # Language settings
4249 #
4350 $wgLanguageCode = "en";
Index: branches/stable/phase3/includes/LinkCache.php
@@ -12,6 +12,16 @@
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+
 21+ /* private */ function getPrefillKey( $title ) {
 22+ global $wgDBname;
 23+ return "$wgDBname:lc:prefill:$title";
 24+ }
 25+
1626 function LinkCache()
1727 {
1828 $this->mActive = true;
@@ -67,6 +77,8 @@
6878 if ( isset( $index ) ) {
6979 unset( $this->mBadLinks[$index] );
7080 }
 81+ global $wgMemc;
 82+ $wgMemc->delete( $this->getKey( $title ) );
7183 }
7284
7385 function suspend() { $this->mActive = false; }
@@ -92,37 +104,54 @@
93105 $id = $this->getGoodLinkID( $title );
94106 if ( 0 != $id ) { return $id; }
95107
96 - wfProfileIn( "LinkCache::addLink-checkdatabase" );
 108+ global $wgMemc;
 109+ $fname = "LinkCache::addLinkObj";
 110+ wfProfileIn( $fname );
97111
98112 $ns = $nt->getNamespace();
99113 $t = $nt->getDBkey();
100114
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;
 115+ if ( "" == $title ) {
 116+ wfProfileOut( $fname );
 117+ return 0;
111118 }
 119+
 120+ $id = $wgMemc->get( $key = $this->getKey( $title ) );
 121+ if( $id === FALSE ) {
 122+ $sql = "SELECT cur_id FROM cur WHERE cur_namespace=" .
 123+ "{$ns} AND cur_title='" . wfStrencode( $t ) . "'";
 124+ $res = wfQuery( $sql, $fname );
 125+
 126+ if ( 0 == wfNumRows( $res ) ) {
 127+ $id = 0;
 128+ } else {
 129+ $s = wfFetchObject( $res );
 130+ $id = $s->cur_id;
 131+ }
 132+ $wgMemc->add( $key, $id, time() + 3600 );
 133+ }
112134 if ( 0 == $id ) { $this->addBadLink( $title ); }
113135 else { $this->addGoodLink( $id, $title ); }
114136 wfProfileOut();
115137 return $id;
116138 }
117139
118 - function preFill( $fromtitle )
 140+ function preFill( &$fromtitle )
119141 {
120 - wfProfileIn( "LinkCache::preFill" );
 142+ $fname = "LinkCache::preFill";
 143+ wfProfileIn( $fname );
121144 # Note -- $fromtitle is a Title *object*
122145 $dbkeyfrom = wfStrencode( $fromtitle->getPrefixedDBKey() );
 146+
 147+ if( $this->preFillFromCache( $dbkeyfrom ) ) {
 148+ wfProfileOut();
 149+ return;
 150+ }
 151+
123152 $sql = "SELECT cur_id,cur_namespace,cur_title
124153 FROM cur,links
125154 WHERE cur_id=l_to AND l_from='{$dbkeyfrom}'";
126 - $res = wfQuery( $sql, "LinkCache::preFill" );
 155+ $res = wfQuery( $sql, $fname );
127156 while( $s = wfFetchObject( $res ) ) {
128157 $this->addGoodLink( $s->cur_id,
129158 Title::makeName( $s->cur_namespace, $s->cur_title )
@@ -135,8 +164,8 @@
136165
137166 $sql = "SELECT bl_to
138167 FROM brokenlinks
139 - WHERE bl_from='{$id}'";
140 - $res = wfQuery( $sql, "LinkCache::preFill" );
 168+ WHERE bl_from={$id}";
 169+ $res = wfQuery( $sql, $fname );
141170 while( $s = wfFetchObject( $res ) ) {
142171 $this->addBadLink( $s->bl_to );
143172 }
@@ -145,8 +174,30 @@
146175 $this->mOldGoodLinks = $this->mGoodLinks;
147176 $this->mPreFilled = true;
148177
 178+ $this->preFillToCache( $dbkeyfrom );
 179+
149180 wfProfileOut();
150181 }
 182+
 183+ function preFillFromCache( $dbkey ) {
 184+ global $wgMemc;
 185+ $prefill = $wgMemc->get( $this->getPrefillKey( $dbkey ) );
 186+ if( $prefill === FALSE ) return false;
 187+ list( $this->mGoodLinks, $this->mBadLinks, $this->mImageLinks ) = $prefill;
 188+ list( $this->mOldGoodLinks, $this->mOldBadLinks ) = $prefill;
 189+ return $this->mPreFilled = true;
 190+ }
 191+
 192+ function preFillToCache( $dbkey ) {
 193+ global $wgMemc;
 194+ $prefill = array( $this->mGoodLinks, $this->mBadLinks, $this->mImageLinks );
 195+ $wgMemc->set( $this->getPrefillKey( $dbkey ), $prefill, time() + 3600 );
 196+ }
 197+
 198+ function clearPreFill( $dbkey ) {
 199+ global $wgMemc;
 200+ $wgMemc->delete( $this->getPrefillKey( $dbkey ) );
 201+ }
151202
152203 function getGoodAdditions()
153204 {
Index: branches/stable/phase3/includes/LinksUpdate.php
@@ -141,6 +141,8 @@
142142 $sql = "COMMIT";
143143 wfQuery( $sql, $fname );
144144 }
 145+
 146+ $wgLinkCache->clearPreFill( $this->mTitleEnc );
145147 wfProfileOut();
146148 }
147149
@@ -216,6 +218,8 @@
217219 $sql = "COMMIT";
218220 wfQuery( $sql, $fname );
219221 }
 222+
 223+ $wgLinkCache->clearPreFill( $this->mTitleEnc );
220224 wfProfileOut();
221225 }
222226
@@ -223,10 +227,11 @@
224228 /* Update any brokenlinks *to* this page */
225229 /* Call for a newly created page, or just to make sure state is consistent */
226230
227 - $sql = "SELECT bl_from FROM brokenlinks WHERE bl_to='{$this->mTitleEnc}'";
 231+ $sql = "SELECT bl_from,cur_namespace,cur_title FROM brokenlinks,cur WHERE bl_to='{$this->mTitleEnc}' and bl_from=cur_id";
228232 $res = wfQuery( $sql, $fname );
229233 if ( 0 == wfNumRows( $res ) ) { return; }
230234
 235+ global $wgLinkCache;
231236 $sql = "INSERT INTO links (l_from,l_to) VALUES ";
232237 $now = wfTimestampNow();
233238 $sql2 = "UPDATE cur SET cur_touched='{$now}' WHERE cur_id IN (";
@@ -238,6 +243,8 @@
239244
240245 $sql .= "('{$nl}',{$this->mId})";
241246 $sql2 .= $row->bl_from;
 247+ $t = Title::makeTitle( $row->cur_namespace, $row->cur_title );
 248+ $wgLinkCache->clearPreFill( $t->getPrefixedDBKey() );
242249 }
243250 $sql2 .= ")";
244251 wfQuery( $sql, $fname );

Status & tagging log