r33008 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r33007‎ | r33008 | r33009 >
Date:05:21, 9 April 2008
Author:aaron
Status:old
Tags:
Comment:
...really get rid of link color query spam
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/LinkBatch.php (modified) (history)
  • /trunk/phase3/includes/LinkCache.php (modified) (history)
  • /trunk/phase3/includes/Parser.php (modified) (history)
  • /trunk/phase3/includes/Parser_OldPP.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/WatchlistEditor.php (modified) (history)
  • /trunk/phase3/includes/filerepo/File.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -305,7 +305,7 @@
306306
307307 $lc =& LinkCache::singleton();
308308 if ( $data ) {
309 - $lc->addGoodLinkObj( $data->page_id, $this->mTitle );
 309+ $lc->addGoodLinkObj( $data->page_id, $this->mTitle, $data->page_len, $data->page_is_redirect );
310310
311311 $this->mTitle->mArticleID = $data->page_id;
312312
Index: trunk/phase3/includes/LinkBatch.php
@@ -96,7 +96,7 @@
9797 $remaining = $this->data;
9898 while ( $row = $res->fetchObject() ) {
9999 $title = Title::newFromRow( $row );
100 - $cache->addGoodLinkObj( $row->page_id, $title );
 100+ $cache->addGoodLinkObj( $row->page_id, $title, $row->page_len, $row->page_is_redirect );
101101 $ids[$title->getPrefixedDBkey()] = $row->page_id;
102102 unset( $remaining[$row->page_namespace][$row->page_title] );
103103 }
Index: trunk/phase3/includes/Parser.php
@@ -4028,7 +4028,7 @@
40294029 while ( $s = $dbr->fetchObject($res) ) {
40304030 $title = Title::newFromRow( $s );
40314031 $pdbk = $title->getPrefixedDBkey();
4032 - $linkCache->addGoodLinkObj( $s->page_id, $title );
 4032+ $linkCache->addGoodLinkObj( $s->page_id, $title, $s->page_len, $s->page_is_redirect );
40334033 $this->mOutput->addLink( $title, $s->page_id );
40344034 $colours[$pdbk] = $sk->getLinkColour( $title, $threshold );
40354035 //add id to the extension todolist
@@ -4110,7 +4110,7 @@
41114111 $holderKeys = array();
41124112 if(isset($variantMap[$varPdbk])){
41134113 $holderKeys = $variantMap[$varPdbk];
4114 - $linkCache->addGoodLinkObj( $s->page_id, $variantTitle );
 4114+ $linkCache->addGoodLinkObj( $s->page_id, $variantTitle, $s->page_len, $s->page_is_redirect );
41154115 $this->mOutput->addLink( $variantTitle, $s->page_id );
41164116 }
41174117
Index: trunk/phase3/includes/WatchlistEditor.php
@@ -217,7 +217,7 @@
218218 if( $title instanceof Title ) {
219219 // Update the link cache while we're at it
220220 if( $row->page_id ) {
221 - $cache->addGoodLinkObj( $row->page_id, $title );
 221+ $cache->addGoodLinkObj( $row->page_id, $title, $row->page_len, $row->page_is_redirect );
222222 } else {
223223 $cache->addBadLinkObj( $title );
224224 }
Index: trunk/phase3/includes/filerepo/File.php
@@ -852,7 +852,7 @@
853853 if ( $db->numRows( $res ) ) {
854854 while ( $row = $db->fetchObject( $res ) ) {
855855 if ( $titleObj = Title::newFromRow( $row ) ) {
856 - $linkCache->addGoodLinkObj( $row->page_id, $titleObj );
 856+ $linkCache->addGoodLinkObj( $row->page_id, $titleObj, $row->page_len, $row->page_is_redirect );
857857 $retVal[] = $titleObj;
858858 }
859859 }
Index: trunk/phase3/includes/Parser_OldPP.php
@@ -4147,7 +4147,7 @@
41484148 while ( $s = $dbr->fetchObject($res) ) {
41494149 $title = Title::newFromRow( $s );
41504150 $pdbk = $title->getPrefixedDBkey();
4151 - $linkCache->addGoodLinkObj( $s->page_id, $title );
 4151+ $linkCache->addGoodLinkObj( $s->page_id, $title, $s->page_len, $s->page_is_redirect );
41524152 $this->mOutput->addLink( $title, $s->page_id );
41534153
41544154 $colours[$pdbk] = ( $threshold == 0 || (
@@ -4230,7 +4230,7 @@
42314231 $holderKeys = array();
42324232 if(isset($variantMap[$varPdbk])){
42334233 $holderKeys = $variantMap[$varPdbk];
4234 - $linkCache->addGoodLinkObj( $s->page_id, $variantTitle );
 4234+ $linkCache->addGoodLinkObj( $s->page_id, $variantTitle, $s->page_len, $s->page_is_redirect );
42354235 $this->mOutput->addLink( $variantTitle, $s->page_id );
42364236 }
42374237
Index: trunk/phase3/includes/Title.php
@@ -86,7 +86,7 @@
8787 $this->mLatestID = false;
8888 $this->mOldRestrictions = false;
8989 $this->mLength = -1;
90 - $this->mRedirect = null;
 90+ $this->mRedirect = NULL;
9191 }
9292
9393 /**
@@ -231,12 +231,12 @@
232232 */
233233 public static function newFromRow( $row ) {
234234 $t = self::makeTitle( $row->page_namespace, $row->page_title );
235 -
236 - $t->mArticleID = isset($row->page_id) ? $row->page_id : -1;
237 - $t->mLength = isset($row->page_len) ? $row->page_len : -1;
238 - $t->mRedirect = isset($row->page_is_redirect) ? (bool)$row->page_is_redirect : null;
239 - $t->mLatest = isset($row->page_latest) ? $row->page_latest : 0;
240 -
 235+
 236+ $t->mArticleID = isset($row->page_id) ? intval($row->page_id) : -1;
 237+ $t->mLength = isset($row->page_len) ? intval($row->page_len) : -1;
 238+ $t->mRedirect = isset($row->page_is_redirect) ? intval($row->page_is_redirect) : NULL;
 239+ $t->mLatestID = isset($row->page_latest) ? $row->page_latest : false;
 240+
241241 return $t;
242242 }
243243
@@ -1482,49 +1482,8 @@
14831483 public function isTalkPage() {
14841484 return MWNamespace::isTalk( $this->getNamespace() );
14851485 }
1486 -
1487 - /**
1488 - * Is this an article that is a redirect page?
1489 - * @return bool
1490 - */
1491 - public function isRedirect() {
1492 - if( $this->mRedirect !== null )
1493 - return $this->mRedirect;
1494 - # Zero for special pages
1495 - if( $this->getNamespace() == NS_SPECIAL )
1496 - return 0;
14971486
1498 - $dbr = wfGetDB( DB_SLAVE );
1499 - $redir = $dbr->selectField( 'page', 'page_is_redirect',
1500 - array( 'page_id' => $this->getArticleId() ),
1501 - __METHOD__ );
1502 -
1503 - $this->mRedirect = (bool)$redir;
1504 -
1505 - return $this->mRedirect;
1506 - }
1507 -
15081487 /**
1509 - * What is the length of this page?
1510 - * @return bool
1511 - */
1512 - public function getLength() {
1513 - if( $this->mLength != -1 || $this->mArticleID == 0 )
1514 - return $this->mLength;
1515 - # Zero for special pages
1516 - if( $this->getNamespace() == NS_SPECIAL )
1517 - return 0;
1518 -
1519 - $dbr = wfGetDB( DB_SLAVE );
1520 - $len = $dbr->selectField( 'page', 'page_len',
1521 - array( 'page_id' => $this->getArticleId() ),
1522 - __METHOD__ );
1523 - $this->mLength = intval($len);
1524 -
1525 - return $this->mLength;
1526 - }
1527 -
1528 - /**
15291488 * Is this a subpage?
15301489 * @return bool
15311490 */
@@ -1889,7 +1848,43 @@
18901849 }
18911850 return $this->mArticleID;
18921851 }
 1852+
 1853+ /**
 1854+ * Is this an article that is a redirect page?
 1855+ * Uses link cache, adding it if necessary
 1856+ * @param int $flags a bit field; may be GAID_FOR_UPDATE to select for update
 1857+ * @return bool
 1858+ */
 1859+ public function isRedirect( $flags = 0 ) {
 1860+ # Zero for special pages.
 1861+ # Also, calling getArticleID() loads the field from cache!
 1862+ if( !$this->getArticleID($flags) || $this->getNamespace() == NS_SPECIAL ) {
 1863+ return false;
 1864+ }
 1865+ $linkCache =& LinkCache::singleton();
 1866+ $this->mRedirect = $linkCache->getGoodLinkFieldObj( $this, 'redirect' );
18931867
 1868+ return (bool)$this->mRedirect;
 1869+ }
 1870+
 1871+ /**
 1872+ * What is the length of this page?
 1873+ * Uses link cache, adding it if necessary
 1874+ * @param int $flags a bit field; may be GAID_FOR_UPDATE to select for update
 1875+ * @return bool
 1876+ */
 1877+ public function getLength( $flags = 0 ) {
 1878+ # Zero for special pages.
 1879+ # Also, calling getArticleID() loads the field from cache!
 1880+ if( !$this->getArticleID($flags) || $this->getNamespace() == NS_SPECIAL ) {
 1881+ return 0;
 1882+ }
 1883+ $linkCache =& LinkCache::singleton();
 1884+ $this->mLength = $linkCache->getGoodLinkFieldObj( $this, 'length' );
 1885+
 1886+ return intval($this->mLength);
 1887+ }
 1888+
18941889 public function getLatestRevID() {
18951890 if ($this->mLatestID !== false)
18961891 return $this->mLatestID;
@@ -2245,7 +2240,7 @@
22462241 if ( $db->numRows( $res ) ) {
22472242 while ( $row = $db->fetchObject( $res ) ) {
22482243 if ( $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title ) ) {
2249 - $linkCache->addGoodLinkObj( $row->page_id, $titleObj );
 2244+ $linkCache->addGoodLinkObj( $row->page_id, $titleObj, $row->page_len, $row->page_is_redirect );
22502245 $retVal[] = $titleObj;
22512246 }
22522247 }
Index: trunk/phase3/includes/LinkCache.php
@@ -7,7 +7,7 @@
88 class LinkCache {
99 // Increment $mClassVer whenever old serialized versions of this class
1010 // becomes incompatible with the new version.
11 - /* private */ var $mClassVer = 3;
 11+ /* private */ var $mClassVer = 4;
1212
1313 /* private */ var $mPageLinks;
1414 /* private */ var $mGoodLinks, $mBadLinks;
@@ -28,6 +28,7 @@
2929 $this->mForUpdate = false;
3030 $this->mPageLinks = array();
3131 $this->mGoodLinks = array();
 32+ $this->mGoodLinkFields = array();
3233 $this->mBadLinks = array();
3334 }
3435
@@ -49,14 +50,38 @@
5051 return 0;
5152 }
5253 }
 54+
 55+ /**
 56+ * Get a field of a title object from cache.
 57+ * If this link is not good, it will return NULL.
 58+ * @param Title $title
 59+ * @param string $field ('length','redirect')
 60+ * @return mixed
 61+ */
 62+ function getGoodLinkFieldObj( $title, $field ) {
 63+ $dbkey = $title->getPrefixedDbKey();
 64+ if ( array_key_exists( $dbkey, $this->mGoodLinkFields ) ) {
 65+ return $this->mGoodLinkFields[$dbkey][$field];
 66+ } else {
 67+ return NULL;
 68+ }
 69+ }
5370
5471 function isBadLink( $title ) {
5572 return array_key_exists( $title, $this->mBadLinks );
5673 }
5774
58 - function addGoodLinkObj( $id, $title ) {
 75+ /**
 76+ * Add a link for the title to the link cache
 77+ * @param int $id
 78+ * @param Title $title
 79+ * @param int $len
 80+ * @param int $redir
 81+ */
 82+ function addGoodLinkObj( $id, $title, $len = -1, $redir = NULL ) {
5983 $dbkey = $title->getPrefixedDbKey();
6084 $this->mGoodLinks[$dbkey] = $id;
 85+ $this->mGoodLinkFields[$dbkey] = array( 'length' => $len, 'redirect' => $redir );
6186 $this->mPageLinks[$dbkey] = $title;
6287 }
6388
@@ -124,11 +149,15 @@
125150 wfProfileOut( $fname );
126151 return 0;
127152 }
128 -
 153+ # Some fields heavily used for linking...
129154 $id = NULL;
130 - if( $wgLinkCacheMemcached )
 155+ $len = -1;
 156+ $redirect = NULL;
 157+
 158+ if( $wgLinkCacheMemcached ) {
131159 $id = $wgMemc->get( $key = $this->getKey( $title ) );
132 - if( ! is_integer( $id ) ) {
 160+ }
 161+ if( !is_integer( $id ) ) {
133162 if ( $this->mForUpdate ) {
134163 $db = wfGetDB( DB_MASTER );
135164 if ( !( $wgAntiLockFlags & ALF_NO_LINK_LOCK ) ) {
@@ -141,20 +170,24 @@
142171 $options = array();
143172 }
144173
145 - $id = $db->selectField( 'page', 'page_id',
146 - array( 'page_namespace' => $ns, 'page_title' => $t ),
147 - $fname, $options );
148 - if ( !$id ) {
149 - $id = 0;
 174+ $s = $db->selectRow( 'page',
 175+ array( 'page_id', 'page_len', 'page_is_redirect' ),
 176+ array( 'page_namespace' => $ns, 'page_title' => $t ),
 177+ $fname, $options );
 178+ # Set fields...
 179+ $id = $s ? $s->page_id : 0;
 180+ $len = $s ? $s->page_len : -1;
 181+ $redirect = $s ? $s->page_is_redirect : 0;
 182+
 183+ if( $wgLinkCacheMemcached ) {
 184+ $wgMemc->add( $key, $id, 3600*24 );
150185 }
151 - if( $wgLinkCacheMemcached )
152 - $wgMemc->add( $key, $id, 3600*24 );
153186 }
154187
155188 if( 0 == $id ) {
156189 $this->addBadLinkObj( $nt );
157190 } else {
158 - $this->addGoodLinkObj( $id, $nt );
 191+ $this->addGoodLinkObj( $id, $nt, $len, $redirect );
159192 }
160193 wfProfileOut( $fname );
161194 return $id;
@@ -166,6 +199,7 @@
167200 function clear() {
168201 $this->mPageLinks = array();
169202 $this->mGoodLinks = array();
 203+ $this->mGoodLinkFields = array();
170204 $this->mBadLinks = array();
171205 }
172206 }

Status & tagging log