r45777 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r45776‎ | r45777 | r45778 >
Date:17:49, 15 January 2009
Author:mkroetzsch
Status:deferred
Tags:
Comment:
avoid repeated queries when using many ?Category:Someting printouts (even if chached, these requests have an effect on overall performance, since they
are done for every result in a query)
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
@@ -284,19 +284,25 @@
285285 $result = new SMWQueryResult($prs, $query, ($count > $query->getLimit()) );
286286 foreach ($qr as $qt) {
287287 $row = array();
 288+ $cats = false;
288289 foreach ($prs as $pr) {
289290 switch ($pr->getMode()) {
290291 case SMWPrintRequest::PRINT_THIS:
291292 $row[] = new SMWResultArray(array($qt), $pr);
292293 break;
293294 case SMWPrintRequest::PRINT_CATS:
294 - $row[] = new SMWResultArray($this->m_store->getPropertyValues($qt,SMWPropertyValue::makeProperty('_INST')), $pr);
 295+ if ($cats === false) {
 296+ $cats = $this->m_store->getPropertyValues($qt,SMWPropertyValue::makeProperty('_INST'));
 297+ }
 298+ $row[] = new SMWResultArray($cats, $pr);
295299 break;
296300 case SMWPrintRequest::PRINT_PROP:
297301 $row[] = new SMWResultArray($this->m_store->getPropertyValues($qt,$pr->getData(), NULL, $pr->getOutputFormat()), $pr);
298302 break;
299303 case SMWPrintRequest::PRINT_CCAT:
300 - $cats = $this->m_store->getPropertyValues($qt,SMWPropertyValue::makeProperty('_INST'));
 304+ if ($cats === false) {
 305+ $cats = $this->m_store->getPropertyValues($qt,SMWPropertyValue::makeProperty('_INST'));
 306+ }
301307 $found = '0';
302308 foreach ($cats as $cat) {
303309 if ($cat->getDBkey() == $pr->getData()->getDBkey()) {
@@ -391,12 +397,12 @@
392398 array('s_id'=>$cid), 'SMWSQLStore2Queries::compileQueries');
393399 if ( $row === false ) { // no description found, concept does not exist
394400 // keep the above query object, it yields an empty result
395 - ///TODO: announce an error here? (maybe not, since the query processor can check for
 401+ ///TODO: announce an error here? (maybe not, since the query processor can check for
396402 ///non-existing concept pages which is probably the main reason for finding nothing here
397403 } else {
398404 global $smwgQConceptCaching, $smwgQMaxSize, $smwgQMaxDepth, $smwgQFeatures, $smwgQConceptCacheLifetime;
399405 $may_be_computed = ($smwgQConceptCaching == CONCEPT_CACHE_NONE) ||
400 - ( ($smwgQConceptCaching == CONCEPT_CACHE_HARD) && ( (~(~($row->concept_features+0) | $smwgQFeatures)) == 0) &&
 406+ ( ($smwgQConceptCaching == CONCEPT_CACHE_HARD) && ( (~(~($row->concept_features+0) | $smwgQFeatures)) == 0) &&
401407 ($smwgQMaxSize >= $row->concept_size) && ($smwgQMaxDepth >= $row->concept_depth));
402408 if ($row->cache_date &&
403409 ($row->cache_date > (strtotime("now") - $smwgQConceptCacheLifetime*60) ||
@@ -654,7 +660,7 @@
655661 $sql = "INSERT IGNORE INTO " . $this->m_dbs->tableName($query->alias) . " SELECT $subquery->joinfield FROM " .
656662 $this->m_dbs->tableName($subquery->jointable) . " AS $subquery->alias $subquery->from" . ($subquery->where?" WHERE $subquery->where":'');
657663 } elseif ($subquery->joinfield !== '') {
658 - /// NOTE: this works only for single "unconditional" values without further
 664+ /// NOTE: this works only for single "unconditional" values without further
659665 /// WHERE or FROM. The execution must take care of not creating any others.
660666 $values = '';
661667 foreach ($subquery->joinfield as $value) {
@@ -680,7 +686,7 @@
681687 case SMW_SQL2_VALUE: break; // nothing to do
682688 }
683689 }
684 -
 690+
685691 /**
686692 * Find subproperties or subcategories. This may require iterative computation,
687693 * and temporary tables are used in many cases.
@@ -732,7 +738,7 @@
733739
734740 /// NOTE: we use two helper tables. One holds the results of each new iteration, one holds the
735741 /// results of the previous iteration. One could of course do with only the above result table,
736 - /// but then every iteration would use all elements of this table, while only the new ones
 742+ /// but then every iteration would use all elements of this table, while only the new ones
737743 /// obtained in the previous step are relevant. So this is a performance measure.
738744 $tmpnew = 'smw_new';
739745 $tmpres = 'smw_res';
@@ -767,8 +773,8 @@
768774 }
769775
770776 /**
771 - * This function modifies the given query object at $qid to account for all ordering conditions
772 - * in the SMWQuery $query. It is always required that $qid is the id of a query that joins with
 777+ * This function modifies the given query object at $qid to account for all ordering conditions
 778+ * in the SMWQuery $query. It is always required that $qid is the id of a query that joins with
773779 * smw_ids so that the field alias.smw_title is $available for default sorting.
774780 */
775781 protected function applyOrderConditions($query, $qid) {

Status & tagging log