r24956 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24955‎ | r24956 | r24957 >
Date:16:34, 20 August 2007
Author:mkroetzsch
Status:old
Tags:
Comment:
More profiling.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
@@ -110,18 +110,25 @@
111111 * being part of some special search page.
112112 */
113113 static public function getResultHTML($querystring, $params, $inline = true) {
 114+ wfProfileIn('SMWQueryProcessor::getResultHTML (SMW)');
114115 $format = SMWQueryProcessor::getResultFormat($params);
115116 $query = SMWQueryProcessor::createQuery($querystring, $params, $inline, $format);
116117 if ($query instanceof SMWQuery) { // query parsing successful
117118 $res = smwfGetStore()->getQueryResult($query);
118119 if ($query->querymode == SMWQuery::MODE_INSTANCES) {
 120+ wfProfileIn('SMWQueryProcessor::getResultHTML-printout (SMW)');
119121 $printer = SMWQueryProcessor::getResultPrinter($format, $inline, $res);
120 - return $printer->getResultHTML($res, $params);
 122+ $result = $printer->getResultHTML($res, $params);
 123+ wfProfileOut('SMWQueryProcessor::getResultHTML-printout (SMW)');
 124+ wfProfileOut('SMWQueryProcessor::getResultHTML (SMW)');
 125+ return $result;
121126 } else { // result for counting or debugging is just a string
 127+ wfProfileOut('SMWQueryProcessor::getResultHTML (SMW)');
122128 return $res;
123129 }
124130 } else { // error string (should be HTML-safe)
125 - return $query; ///TODO: improve error reporting format ...
 131+ wfProfileOut('SMWQueryProcessor::getResultHTML (SMW)');
 132+ return $query;
126133 }
127134 }
128135
@@ -205,12 +212,15 @@
206213 * false if there were errors.
207214 */
208215 public function getQueryDescription($querystring) {
 216+ wfProfileIn('SMWQueryParser::getQueryDescription (SMW)');
209217 $this->m_errors = array();
210218 $this->m_label = '';
211219 $this->m_curstring = $querystring;
212220 $this->m_sepstack = array();
213221 $setNS = true;
214 - return $this->getSubqueryDescription($setNS, $this->m_label);
 222+ $result = $this->getSubqueryDescription($setNS, $this->m_label);
 223+ wfProfileOut('SMWQueryParser::getQueryDescription (SMW)');
 224+ return $result;
215225 }
216226
217227 /**
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php
@@ -51,6 +51,7 @@
5252 ///// Reading methods /////
5353
5454 function getSpecialValues(Title $subject, $specialprop, $requestoptions = NULL) {
 55+ wfProfileIn("SMWSQLStore::getSpecialValues-$specialprop (SMW)");
5556 $db =& wfGetDB( DB_SLAVE ); // TODO: Is '=&' needed in PHP5?
5657
5758 // NOTE: this method currently supports no ordering or boundary. This is probably best anyway ...
@@ -109,22 +110,25 @@
110111 }
111112 $db->freeResult($res);
112113 }
 114+ wfProfileOut("SMWSQLStore::getSpecialValues-$specialprop (SMW)");
113115 return $result;
114116 }
115117
116118 function getSpecialSubjects($specialprop, $value, $requestoptions = NULL) {
 119+ wfProfileIn("SMWSQLStore::getSpecialSubjects-$specialprop (SMW)");
117120 $db =& wfGetDB( DB_SLAVE );
118121
119122 $result = array();
120123
121124 if ($specialprop === SMW_SP_HAS_CATEGORY) { // category membership
122125 if ( !($value instanceof Title) || ($value->getNamespace() != NS_CATEGORY) ) {
 126+ wfProfileOut("SMWSQLStore::getSpecialSubjects-$specialprop (SMW)");
123127 return array();
124128 }
125129 $sql = 'cl_to=' . $db->addQuotes($value->getDBKey());
126130 $res = $db->select( 'categorylinks',
127131 'DISTINCT cl_from',
128 - $sql, 'SMW::getSpecialValues', $this->getSQLOptions($requestoptions) );
 132+ $sql, 'SMW::getSpecialSubjects', $this->getSQLOptions($requestoptions) );
129133 // rewrite result as array
130134 while($row = $db->fetchObject($res)) {
131135 $result[] = Title::newFromID($row->cl_from);
@@ -135,7 +139,7 @@
136140 . ' AND rd_namespace=' . $db->addQuotes($value->getNamespace());
137141 $res = $db->select( 'redirect',
138142 'rd_from',
139 - $sql, 'SMW::getSpecialValues', $this->getSQLOptions($requestoptions) );
 143+ $sql, 'SMW::getSpecialSubjects', $this->getSQLOptions($requestoptions) );
140144 // reqrite results as array
141145 while($row = $db->fetchObject($res)) {
142146 $result[] = Title::newFromID($row->rd_from);
@@ -145,7 +149,7 @@
146150 $sql = 'object_title=' . $db->addQuotes($value->getDBKey());
147151 $res = $db->select( 'smw_subprops',
148152 'subject_title',
149 - $sql, 'SMW::getSpecialValues', $this->getSQLOptions($requestoptions) );
 153+ $sql, 'SMW::getSpecialSubjects', $this->getSQLOptions($requestoptions) );
150154 // reqrite results as array
151155 while($row = $db->fetchObject($res)) {
152156 $result[] = Title::makeTitle(SMW_NS_PROPERTY, $row->subject_title);
@@ -156,6 +160,7 @@
157161 if ($value->getXSDValue() !== false) { // filters out error-values etc.
158162 $stringvalue = $value->getXSDValue();
159163 } else {
 164+ wfProfileOut("SMWSQLStore::getSpecialSubjects-$specialprop (SMW)");
160165 return array();
161166 }
162167 } elseif ($value instanceof Title) {
@@ -179,12 +184,13 @@
180185 }
181186 $db->freeResult($res);
182187 }
183 -
 188+ wfProfileOut("SMWSQLStore::getSpecialSubjects-$specialprop (SMW)");
184189 return $result;
185190 }
186191
187192
188193 function getPropertyValues(Title $subject, Title $property, $requestoptions = NULL, $outputformat = '') {
 194+ wfProfileIn("SMWSQLStore::getPropertyValues (SMW)");
189195 $db =& wfGetDB( DB_SLAVE );
190196 $result = array();
191197
@@ -301,17 +307,21 @@
302308 }
303309 $db->freeResult($res);
304310 }
 311+ wfProfileOut("SMWSQLStore::getPropertyValues (SMW)");
305312 return $result;
306313 }
307314
308315 function getPropertySubjects(Title $property, SMWDataValue $value, $requestoptions = NULL) {
 316+ wfProfileIn("SMWSQLStore::getPropertySubjects (SMW)");
309317 if ( !$value->isValid() ) {
 318+ wfProfileOut("SMWSQLStore::getPropertySubjects (SMW)");
310319 return array();
311320 }
312321 $db =& wfGetDB( DB_SLAVE );
313322
314323 switch ($value->getTypeID()) {
315324 case '_txt': // not supported
 325+ wfProfileOut("SMWSQLStore::getPropertySubjects (SMW)");
316326 return array();
317327 break;
318328 case '_wpg': // wikipage
@@ -373,10 +383,12 @@
374384 $result[] = Title::newFromID($row->subject_id);
375385 }
376386 $db->freeResult($res);
 387+ wfProfileOut("SMWSQLStore::getPropertySubjects (SMW)");
377388 return $result;
378389 }
379390
380391 function getAllPropertySubjects(Title $property, $requestoptions = NULL) {
 392+ wfProfileIn("SMWSQLStore::getAllPropertySubjects (SMW)");
381393 $db =& wfGetDB( DB_SLAVE );
382394 $id = SMWDataValueFactory::getPropertyObjectTypeID($property);
383395 switch ($id) {
@@ -411,10 +423,12 @@
412424 $result[] = Title::newFromId($row->subject_id);
413425 }
414426 $db->freeResult($res);
 427+ wfProfileOut("SMWSQLStore::getAllPropertySubjects (SMW)");
415428 return $result;
416429 }
417430
418431 function getProperties(Title $subject, $requestoptions = NULL) {
 432+ wfProfileIn("SMWSQLStore::getProperties (SMW)");
419433 $db =& wfGetDB( DB_SLAVE );
420434 $sql = 'subject_id=' . $db->addQuotes($subject->getArticleID()) . $this->getSQLConditions($requestoptions,'attribute_title','attribute_title');
421435
@@ -458,11 +472,12 @@
459473 }
460474 }
461475 $db->freeResult($res);
462 -
 476+ wfProfileOut("SMWSQLStore::getProperties (SMW)");
463477 return $result;
464478 }
465479
466480 function getInProperties(SMWDataValue $value, $requestoptions = NULL) {
 481+ wfProfileIn("SMWSQLStore::getInProperties (SMW)");
467482 $db =& wfGetDB( DB_SLAVE );
468483 $result = array();
469484 if ($value->getTypeID() == '_wpg') {
@@ -478,12 +493,14 @@
479494 }
480495 $db->freeResult($res);
481496 }
 497+ wfProfileOut("SMWSQLStore::getInProperties (SMW)");
482498 return $result;
483499 }
484500
485501 ///// Writing methods /////
486502
487503 function deleteSubject(Title $subject) {
 504+ wfProfileIn("SMWSQLStore::deleteSubjects (SMW)");
488505 $db =& wfGetDB( DB_MASTER );
489506 $db->delete('smw_relations',
490507 array('subject_id' => $subject->getArticleID()),
@@ -518,9 +535,11 @@
519536 array('subject_title' => $subject->getDBKey()),
520537 'SMW::deleteSubject::Subprops');
521538 }
 539+ wfProfileOut("SMWSQLStore::deleteSubjects (SMW)");
522540 }
523541
524542 function updateData(SMWSemanticData $data) {
 543+ wfProfileOut("SMWSQLStore::updateData (SMW)");
525544 $db =& wfGetDB( DB_MASTER );
526545 $subject = $data->getSubject();
527546 $this->deleteSubject($subject);
@@ -683,9 +702,11 @@
684703 if (count($up_nary_longstrings) > 0) {
685704 $db->insert( 'smw_nary_longstrings', $up_nary_longstrings, 'SMW::updateNAryLongData');
686705 }
 706+ wfProfileOut("SMWSQLStore::updateData (SMW)");
687707 }
688708
689709 function changeTitle(Title $oldtitle, Title $newtitle, $keepid = true) {
 710+ wfProfileIn("SMWSQLStore::changeTitle (SMW)");
690711 $db =& wfGetDB( DB_MASTER );
691712
692713 $cond_array = array( 'subject_title' => $oldtitle->getDBkey(),
@@ -726,6 +747,7 @@
727748 $db->delete('smw_subprops', array('subject_title' => $oldtitle->getDBKey()), 'SMW::changeTitle');
728749 }
729750 }
 751+ wfProfileOut("SMWSQLStore::changeTitle (SMW)");
730752 }
731753
732754 ///// Query answering /////
@@ -737,6 +759,7 @@
738760 * NOTE: we do not support category wildcards, as they have no useful semantics in OWL/RDFS/LP/whatever
739761 */
740762 function getQueryResult(SMWQuery $query) {
 763+ wfProfileIn('SMWSQLStore::getQueryResult (SMW)');
741764 global $smwgQSortingSupport;
742765
743766 $db =& wfGetDB( DB_SLAVE );
@@ -774,7 +797,10 @@
775798 'SMW::getQueryResult',
776799 $sql_options );
777800 $row = $db->fetchObject($res);
778 - return $row->count;
 801+ $count = $row->count;
 802+ $db->freeResult($res);
 803+ wfProfileOut('SMWSQLStore::getQueryResult (SMW)');
 804+ return $count;
779805 // TODO: report query errors?
780806 } elseif ($query->querymode == SMWQuery::MODE_DEBUG) { /// TODO: internationalise
781807 list( $startOpts, $useIndex, $tailOpts ) = $db->makeSelectOptions( $sql_options );
@@ -804,6 +830,7 @@
805831 $result .= '<br />';
806832 }
807833 $result .= '</div>';
 834+ wfProfileOut('SMWSQLStore::getQueryResult (SMW)');
808835 return $result;
809836 } // else: continue
810837
@@ -847,13 +874,14 @@
848875 }
849876 $result->addRow($row);
850877 }
851 -
 878+ wfProfileOut('SMWSQLStore::getQueryResult (SMW)');
852879 return $result;
853880 }
854881
855882 ///// Special page functions /////
856883
857884 function getPropertiesSpecial($requestoptions = NULL) {
 885+ wfProfileIn("SMWSQLStore::getPropertiesSpecial (SMW)");
858886 $db =& wfGetDB( DB_SLAVE );
859887 $options = ' ORDER BY title';
860888 if ($requestoptions->limit >= 0) {
@@ -877,10 +905,12 @@
878906 $result[] = array($title, $row->count);
879907 }
880908 $db->freeResult($res);
 909+ wfProfileOut("SMWSQLStore::getPropertiesSpecial (SMW)");
881910 return $result;
882911 }
883912
884913 function getUnusedPropertiesSpecial($requestoptions = NULL) {
 914+ wfProfileIn("SMWSQLStore::getUnusedPropertiesSpecial (SMW)");
885915 /// FIXME filter out the builtin properties!
886916 $db =& wfGetDB( DB_SLAVE );
887917 $options = ' ORDER BY page_title';
@@ -905,10 +935,12 @@
906936 while($row = $db->fetchObject($res)) {
907937 $result[] = Title::newFromText($row->page_title, SMW_NS_PROPERTY);
908938 }
 939+ wfProfileOut("SMWSQLStore::getUnusedPropertiesSpecial (SMW)");
909940 return $result;
910941 }
911942
912943 function getWantedPropertiesSpecial($requestoptions = NULL) {
 944+ wfProfileIn("SMWSQLStore::getWantedPropertiesSpecial (SMW)");
913945 $db =& wfGetDB( DB_SLAVE );
914946 $options = ' ORDER BY count DESC';
915947 if ($requestoptions->limit >= 0) {
@@ -926,10 +958,12 @@
927959 $title = Title::newFromText($row->title, SMW_NS_PROPERTY);
928960 $result[] = array($title, $row->count);
929961 }
 962+ wfProfileOut("SMWSQLStore::getWantedPropertiesSpecial (SMW)");
930963 return $result;
931964 }
932965
933966 function getStatistics() {
 967+ wfProfileIn("SMWSQLStore::getStatistics (SMW)");
934968 $db =& wfGetDB( DB_SLAVE );
935969 $result = array();
936970 extract( $db->tableNames('smw_relations', 'smw_attributes', 'smw_longstrings', 'smw_nary', 'smw_specialprops') );
@@ -975,6 +1009,7 @@
9761010 $result['DECLPROPS'] = $row->count;
9771011 $db->freeResult( $res );
9781012
 1013+ wfProfileOut("SMWSQLStore::getStatistics (SMW)");
9791014 return $result;
9801015 }
9811016
@@ -1183,6 +1218,7 @@
11841219 * wrt. the category table.
11851220 */
11861221 protected function getCategoryTable($catname, &$db) {
 1222+ wfProfileIn("SMWSQLStore::getCategoryTable (SMW)");
11871223 global $wgDBname, $smwgQSubcategoryDepth;
11881224
11891225 $tablename = 'cats' . SMWSQLStore::$m_tablenum++;
@@ -1195,6 +1231,7 @@
11961232 SMWSQLStore::$m_categorytables[$catname] .
11971233 '.title FROM ' . SMWSQLStore::$m_categorytables[$catname],
11981234 'SMW::getCategoryTable');
 1235+ wfProfileOut("SMWSQLStore::getCategoryTable (SMW)");
11991236 return $tablename;
12001237 }
12011238
@@ -1234,6 +1271,7 @@
12351272 SMWSQLStore::$m_categorytables[$catname] = $tablename;
12361273 $db->query('DROP TABLE smw_newcats', 'SMW::getCategoryTable');
12371274 $db->query('DROP TABLE smw_rescats', 'SMW::getCategoryTable');
 1275+ wfProfileOut("SMWSQLStore::getCategoryTable (SMW)");
12381276 return $tablename;
12391277 }
12401278
@@ -1242,6 +1280,7 @@
12431281 * wrt. the subproperty relation.
12441282 */
12451283 protected function getPropertyTable($propname, &$db) {
 1284+ wfProfileIn("SMWSQLStore::getPropertyTable (SMW)");
12461285 global $wgDBname, $smwgQSubpropertyDepth;
12471286
12481287 $tablename = 'prop' . SMWSQLStore::$m_tablenum++;
@@ -1254,6 +1293,7 @@
12551294 SMWSQLStore::$m_propertytables[$propname] .
12561295 '.title FROM ' . SMWSQLStore::$m_propertytables[$propname],
12571296 'SMW::getPropertyTable');
 1297+ wfProfileOut("SMWSQLStore::getPropertyTable (SMW)");
12581298 return $tablename;
12591299 }
12601300
@@ -1290,6 +1330,7 @@
12911331 SMWSQLStore::$m_propertytables[$propname] = $tablename;
12921332 $db->query('DROP TABLE smw_new', 'SMW::getPropertyTable');
12931333 $db->query('DROP TABLE smw_res', 'SMW::getPropertyTable');
 1334+ wfProfileOut("SMWSQLStore::getPropertyTable (SMW)");
12941335 return $tablename;
12951336 }
12961337

Status & tagging log