r66672 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66671‎ | r66672 | r66673 >
Date:01:02, 20 May 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Style improvements
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php
@@ -4,6 +4,8 @@
55 * for avoiding twice the amount of code being required on every use of a simple storage function.
66 *
77 * @author Markus Krötzsch
 8+ * @author Jeroen De Dauw
 9+ *
810 * @file
911 * @ingroup SMWStore
1012 */
@@ -88,15 +90,19 @@
8991 */
9092 public function refreshConceptCache( $concept ) {
9193 global $smwgQMaxLimit, $smwgQConceptFeatures, $wgDBtype;
 94+
9295 $cid = $this->m_store->getSMWPageID( $concept->getDBkey(), SMW_NS_CONCEPT, '' );
9396 $cid_c = $this->m_store->getSMWPageID( $concept->getDBkey(), SMW_NS_CONCEPT, '', false );
 97+
9498 if ( $cid != $cid_c ) {
9599 $this->m_errors[] = "Skipping redirect concept.";
96100 return $this->m_errors;
97101 }
 102+
98103 $dv = end( $this->m_store->getPropertyValues( $concept, SMWPropertyValue::makeProperty( '_CONC' ) ) );
99104 $desctxt = ( $dv !== false ) ? $dv->getWikiValue():false;
100105 $this->m_errors = array();
 106+
101107 if ( $desctxt ) { // concept found
102108 $this->m_qmode = SMWQuery::MODE_INSTANCES;
103109 $this->m_queries = array();
@@ -109,13 +115,17 @@
110116 $qp = new SMWQueryParser( $smwgQConceptFeatures );
111117 $desc = $qp->getQueryDescription( $desctxt );
112118 $qid = $this->compileQueries( $desc );
 119+
113120 $this->executeQueries( $this->m_queries[$qid] ); // execute query tree, resolve all dependencies
114121 $qobj = $this->m_queries[$qid];
 122+
115123 if ( $qobj->joinfield === '' ) {
116124 return;
117125 }
 126+
118127 // Update database:
119128 $this->m_dbs->delete( 'smw_conccache', array( 'o_id' => $cid ), 'SMW::refreshConceptCache' );
 129+
120130 if ( $wgDBtype == 'postgres' ) { // PostgresQL: no INSERT IGNORE, check for duplicates explicitly
121131 $where = $qobj->where . ( $qobj->where ? ' AND ':'' ) .
122132 'NOT EXISTS (SELECT NULL FROM ' . $this->m_dbs->tableName( 'smw_conccache' ) .
@@ -124,18 +134,22 @@
125135 } else { // MySQL just uses INSERT IGNORE, no extra conditions
126136 $where = $qobj->where;
127137 }
 138+
128139 $this->m_dbs->query( "INSERT " . ( ( $wgDBtype == 'postgres' ) ? "":"IGNORE " ) . "INTO " . $this->m_dbs->tableName( 'smw_conccache' ) .
129140 " SELECT DISTINCT $qobj->joinfield AS s_id, $cid AS o_id FROM " .
130141 $this->m_dbs->tableName( $qobj->jointable ) . " AS $qobj->alias" . $qobj->from .
131142 ( $where ? " WHERE ":'' ) . $where . " LIMIT $smwgQMaxLimit",
132143 'SMW::refreshConceptCache' );
 144+
133145 $this->m_dbs->update( 'smw_conc2', array( 'cache_date' => strtotime( "now" ), 'cache_count' => $this->m_dbs->affectedRows() ), array( 's_id' => $cid ), 'SMW::refreshConceptCache' );
134146 } else { // just delete old data if there is any
135147 $this->m_dbs->delete( 'smw_conccache', array( 'o_id' => $cid ), 'SMW::refreshConceptCache' );
136148 $this->m_dbs->update( 'smw_conc2', array( 'cache_date' => null, 'cache_count' => null ), array( 's_id' => $cid ), 'SMW::refreshConceptCache' );
137149 $this->m_errors[] = "No concept description found.";
138150 }
 151+
139152 $this->cleanUp();
 153+
140154 return $this->m_errors;
141155 }
142156
@@ -315,17 +329,22 @@
316330 */
317331 protected function getCountQueryResult( SMWQuery $query, $rootid ) {
318332 wfProfileIn( 'SMWSQLStore2Queries::getCountQueryResult (SMW)' );
 333+
319334 $qobj = $this->m_queries[$rootid];
 335+
320336 if ( $qobj->joinfield === '' ) { // empty result, no query needed
321337 wfProfileOut( 'SMWSQLStore2Queries::getCountQueryResult (SMW)' );
322338 return 0;
323339 }
 340+
324341 $sql_options = array( 'LIMIT' => $query->getLimit() + 1, 'OFFSET' => $query->getOffset() );
325342 $res = $this->m_dbs->select( $this->m_dbs->tableName( $qobj->jointable ) . " AS $qobj->alias" . $qobj->from, "COUNT(DISTINCT $qobj->alias.smw_id) AS count", $qobj->where, 'SMW::getQueryResult', $sql_options );
326343 $row = $this->m_dbs->fetchObject( $res );
327344 $count = $row->count;
328345 $this->m_dbs->freeResult( $res );
 346+
329347 wfProfileOut( 'SMWSQLStore2Queries::getCountQueryResult (SMW)' );
 348+
330349 return $count;
331350 }
332351
@@ -502,12 +521,14 @@
503522 if ( $row->cache_date &&
504523 ( ( $row->cache_date > ( strtotime( "now" ) - $smwgQConceptCacheLifetime * 60 ) ) ||
505524 !$may_be_computed ) ) { // Cached concept, use cache unless it is dead and can be revived.
 525+
506526 $query->jointable = 'smw_conccache';
507527 $query->joinfield = "$query->alias.s_id";
508528 $query->where = "$query->alias.o_id=" . $this->m_dbs->addQuotes( $cid );
509529 } elseif ( $row->concept_txt ) { // Parse description and process it recursively.
510530 if ( $may_be_computed ) {
511531 $qp = new SMWQueryParser();
 532+
512533 //No defaultnamespaces here; If any, these are already in the concept.
513534 $desc = $qp->getQueryDescription( $row->concept_txt );
514535 $qid = $this->compileQueries( $desc );
@@ -524,6 +545,7 @@
525546
526547 if ( $qid >= 0 ) { // Success, keep query object, propagate sortkeys from subqueries.
527548 $this->m_queries[$qid] = $query;
 549+
528550 if ( $query->type != SMW_SQL2_DISJUNCTION ) { // Sortkeys are killed by disjunctions (not all parts may have them),
529551 // NOTE: preprocessing might try to push disjunctions downwards to safe sortkey, but this seems to be minor
530552 foreach ( $query->components as $cid => $field ) {
@@ -1094,6 +1116,7 @@
10951117 */
10961118 protected function getCreateTempIDTableSQL( $tablename ) {
10971119 global $wgDBtype;
 1120+
10981121 if ( $wgDBtype == 'postgres' ) { // PostgreSQL: no memory tables, use RULE to emulate INSERT IGNORE
10991122 return "CREATE OR REPLACE FUNCTION create_" . $tablename . "() RETURNS void AS "
11001123 . "$$ "

Status & tagging log