r80936 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80935‎ | r80936 | r80937 >
Date:23:15, 24 January 2011
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
Couple more raw SQL to query arrays
Modified paths:
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/parser/LinkHolderArray.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/LinkHolderArray.php
@@ -371,11 +371,12 @@
372372 if(!$linkBatch->isEmpty()){
373373 // construct query
374374 $dbr = wfGetDB( DB_SLAVE );
375 - $page = $dbr->tableName( 'page' );
376 - $titleClause = $linkBatch->constructSet('page', $dbr);
377 - $variantQuery = "SELECT page_id, page_namespace, page_title, page_is_redirect, page_len";
378 - $variantQuery .= " FROM $page WHERE $titleClause";
379 - $varRes = $dbr->query( $variantQuery, __METHOD__ );
 375+ $varRes = $dbr->select( 'page',
 376+ array( 'page_id', 'page_namespace', 'page_title', 'page_is_redirect', 'page_len' ),
 377+ $linkBatch->constructSet( 'page', $dbr ),
 378+ __METHOD__
 379+ );
 380+
380381 $linkcolour_ids = array();
381382
382383 // for each found variants, figure out link holders and replace
@@ -386,14 +387,14 @@
387388 $vardbk = $variantTitle->getDBkey();
388389
389390 $holderKeys = array();
390 - if(isset($variantMap[$varPdbk])){
 391+ if( isset( $variantMap[$varPdbk] ) ) {
391392 $holderKeys = $variantMap[$varPdbk];
392393 $linkCache->addGoodLinkObj( $s->page_id, $variantTitle, $s->page_len, $s->page_is_redirect );
393394 $output->addLink( $variantTitle, $s->page_id );
394395 }
395396
396397 // loop over link holders
397 - foreach($holderKeys as $key){
 398+ foreach( $holderKeys as $key ) {
398399 list( $ns, $index ) = explode( ':', $key, 2 );
399400 $entry =& $this->internals[$ns][$index];
400401 $pdbk = $entry['pdbk'];
Index: trunk/phase3/includes/OutputPage.php
@@ -997,12 +997,12 @@
998998
999999 # Fetch existence plus the hiddencat property
10001000 $dbr = wfGetDB( DB_SLAVE );
1001 - $pageTable = $dbr->tableName( 'page' );
1002 - $where = $lb->constructSet( 'page', $dbr );
1003 - $propsTable = $dbr->tableName( 'page_props' );
1004 - $sql = "SELECT page_id, page_namespace, page_title, page_len, page_is_redirect, page_latest, pp_value
1005 - FROM $pageTable LEFT JOIN $propsTable ON pp_propname='hiddencat' AND pp_page=page_id WHERE $where";
1006 - $res = $dbr->query( $sql, __METHOD__ );
 1001+ $res = $dbr->select( array( 'page', 'page_props' ),
 1002+ array( 'page_id', 'page_namespace', 'page_title', 'page_len', 'page_is_redirect', 'page_latest', 'pp_value' ),
 1003+ $lb->constructSet( 'page', $dbr ),
 1004+ __METHOD__,
 1005+ array( 'LEFT JOIN' => array( "pp_propname='hiddencat'", "pp_page=page_id" ) )
 1006+ );
10071007
10081008 # Add the results to the link cache
10091009 $lb->addResultToCache( LinkCache::singleton(), $res );

Follow-up revisions

RevisionCommit summaryAuthorDate
r81067Fixup query fail from r80936reedy23:13, 26 January 2011
r81169Follow up r81100. Don't hardcode hiddencat quotes, per r80936 CR.platonides22:17, 28 January 2011

Comments

#Comment by Platonides (talk | contribs)   22:41, 26 January 2011

Breaks the test 'Simple category'. Acts as if (added in parserTests.txt) doesn't exists.

+ array( 'LEFT JOIN' => array( "pp_propname='hiddencat'", "pp_page=page_id" ) )

This array is passed as the wrong parameter, and isn't taking part of the generated SQL (ie. there's no LEFT JOIN or pp_propname='hiddencat'/pp_page=page_id there).

So it is probably taking as missing due to doing an INNER JOIN (without joinable fields!) instead of a LEFT JOIN.

#Comment by Platonides (talk | contribs)   22:17, 27 January 2011

The first change was ok, the second resolved in r81100.

#Comment by Duplicatebug (talk | contribs)   20:44, 28 January 2011

What about addQuotes() for 'hiddencat'? I think it is bad to hardcode that quotes inside the query

#Comment by Platonides (talk | contribs)   22:17, 28 January 2011

Fixed in r81169.

Status & tagging log