Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php |
— | — | @@ -110,18 +110,25 @@ |
111 | 111 | * being part of some special search page. |
112 | 112 | */ |
113 | 113 | static public function getResultHTML($querystring, $params, $inline = true) { |
| 114 | + wfProfileIn('SMWQueryProcessor::getResultHTML (SMW)'); |
114 | 115 | $format = SMWQueryProcessor::getResultFormat($params); |
115 | 116 | $query = SMWQueryProcessor::createQuery($querystring, $params, $inline, $format); |
116 | 117 | if ($query instanceof SMWQuery) { // query parsing successful |
117 | 118 | $res = smwfGetStore()->getQueryResult($query); |
118 | 119 | if ($query->querymode == SMWQuery::MODE_INSTANCES) { |
| 120 | + wfProfileIn('SMWQueryProcessor::getResultHTML-printout (SMW)'); |
119 | 121 | $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; |
121 | 126 | } else { // result for counting or debugging is just a string |
| 127 | + wfProfileOut('SMWQueryProcessor::getResultHTML (SMW)'); |
122 | 128 | return $res; |
123 | 129 | } |
124 | 130 | } else { // error string (should be HTML-safe) |
125 | | - return $query; ///TODO: improve error reporting format ... |
| 131 | + wfProfileOut('SMWQueryProcessor::getResultHTML (SMW)'); |
| 132 | + return $query; |
126 | 133 | } |
127 | 134 | } |
128 | 135 | |
— | — | @@ -205,12 +212,15 @@ |
206 | 213 | * false if there were errors. |
207 | 214 | */ |
208 | 215 | public function getQueryDescription($querystring) { |
| 216 | + wfProfileIn('SMWQueryParser::getQueryDescription (SMW)'); |
209 | 217 | $this->m_errors = array(); |
210 | 218 | $this->m_label = ''; |
211 | 219 | $this->m_curstring = $querystring; |
212 | 220 | $this->m_sepstack = array(); |
213 | 221 | $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; |
215 | 225 | } |
216 | 226 | |
217 | 227 | /** |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php |
— | — | @@ -51,6 +51,7 @@ |
52 | 52 | ///// Reading methods ///// |
53 | 53 | |
54 | 54 | function getSpecialValues(Title $subject, $specialprop, $requestoptions = NULL) { |
| 55 | + wfProfileIn("SMWSQLStore::getSpecialValues-$specialprop (SMW)"); |
55 | 56 | $db =& wfGetDB( DB_SLAVE ); // TODO: Is '=&' needed in PHP5? |
56 | 57 | |
57 | 58 | // NOTE: this method currently supports no ordering or boundary. This is probably best anyway ... |
— | — | @@ -109,22 +110,25 @@ |
110 | 111 | } |
111 | 112 | $db->freeResult($res); |
112 | 113 | } |
| 114 | + wfProfileOut("SMWSQLStore::getSpecialValues-$specialprop (SMW)"); |
113 | 115 | return $result; |
114 | 116 | } |
115 | 117 | |
116 | 118 | function getSpecialSubjects($specialprop, $value, $requestoptions = NULL) { |
| 119 | + wfProfileIn("SMWSQLStore::getSpecialSubjects-$specialprop (SMW)"); |
117 | 120 | $db =& wfGetDB( DB_SLAVE ); |
118 | 121 | |
119 | 122 | $result = array(); |
120 | 123 | |
121 | 124 | if ($specialprop === SMW_SP_HAS_CATEGORY) { // category membership |
122 | 125 | if ( !($value instanceof Title) || ($value->getNamespace() != NS_CATEGORY) ) { |
| 126 | + wfProfileOut("SMWSQLStore::getSpecialSubjects-$specialprop (SMW)"); |
123 | 127 | return array(); |
124 | 128 | } |
125 | 129 | $sql = 'cl_to=' . $db->addQuotes($value->getDBKey()); |
126 | 130 | $res = $db->select( 'categorylinks', |
127 | 131 | 'DISTINCT cl_from', |
128 | | - $sql, 'SMW::getSpecialValues', $this->getSQLOptions($requestoptions) ); |
| 132 | + $sql, 'SMW::getSpecialSubjects', $this->getSQLOptions($requestoptions) ); |
129 | 133 | // rewrite result as array |
130 | 134 | while($row = $db->fetchObject($res)) { |
131 | 135 | $result[] = Title::newFromID($row->cl_from); |
— | — | @@ -135,7 +139,7 @@ |
136 | 140 | . ' AND rd_namespace=' . $db->addQuotes($value->getNamespace()); |
137 | 141 | $res = $db->select( 'redirect', |
138 | 142 | 'rd_from', |
139 | | - $sql, 'SMW::getSpecialValues', $this->getSQLOptions($requestoptions) ); |
| 143 | + $sql, 'SMW::getSpecialSubjects', $this->getSQLOptions($requestoptions) ); |
140 | 144 | // reqrite results as array |
141 | 145 | while($row = $db->fetchObject($res)) { |
142 | 146 | $result[] = Title::newFromID($row->rd_from); |
— | — | @@ -145,7 +149,7 @@ |
146 | 150 | $sql = 'object_title=' . $db->addQuotes($value->getDBKey()); |
147 | 151 | $res = $db->select( 'smw_subprops', |
148 | 152 | 'subject_title', |
149 | | - $sql, 'SMW::getSpecialValues', $this->getSQLOptions($requestoptions) ); |
| 153 | + $sql, 'SMW::getSpecialSubjects', $this->getSQLOptions($requestoptions) ); |
150 | 154 | // reqrite results as array |
151 | 155 | while($row = $db->fetchObject($res)) { |
152 | 156 | $result[] = Title::makeTitle(SMW_NS_PROPERTY, $row->subject_title); |
— | — | @@ -156,6 +160,7 @@ |
157 | 161 | if ($value->getXSDValue() !== false) { // filters out error-values etc. |
158 | 162 | $stringvalue = $value->getXSDValue(); |
159 | 163 | } else { |
| 164 | + wfProfileOut("SMWSQLStore::getSpecialSubjects-$specialprop (SMW)"); |
160 | 165 | return array(); |
161 | 166 | } |
162 | 167 | } elseif ($value instanceof Title) { |
— | — | @@ -179,12 +184,13 @@ |
180 | 185 | } |
181 | 186 | $db->freeResult($res); |
182 | 187 | } |
183 | | - |
| 188 | + wfProfileOut("SMWSQLStore::getSpecialSubjects-$specialprop (SMW)"); |
184 | 189 | return $result; |
185 | 190 | } |
186 | 191 | |
187 | 192 | |
188 | 193 | function getPropertyValues(Title $subject, Title $property, $requestoptions = NULL, $outputformat = '') { |
| 194 | + wfProfileIn("SMWSQLStore::getPropertyValues (SMW)"); |
189 | 195 | $db =& wfGetDB( DB_SLAVE ); |
190 | 196 | $result = array(); |
191 | 197 | |
— | — | @@ -301,17 +307,21 @@ |
302 | 308 | } |
303 | 309 | $db->freeResult($res); |
304 | 310 | } |
| 311 | + wfProfileOut("SMWSQLStore::getPropertyValues (SMW)"); |
305 | 312 | return $result; |
306 | 313 | } |
307 | 314 | |
308 | 315 | function getPropertySubjects(Title $property, SMWDataValue $value, $requestoptions = NULL) { |
| 316 | + wfProfileIn("SMWSQLStore::getPropertySubjects (SMW)"); |
309 | 317 | if ( !$value->isValid() ) { |
| 318 | + wfProfileOut("SMWSQLStore::getPropertySubjects (SMW)"); |
310 | 319 | return array(); |
311 | 320 | } |
312 | 321 | $db =& wfGetDB( DB_SLAVE ); |
313 | 322 | |
314 | 323 | switch ($value->getTypeID()) { |
315 | 324 | case '_txt': // not supported |
| 325 | + wfProfileOut("SMWSQLStore::getPropertySubjects (SMW)"); |
316 | 326 | return array(); |
317 | 327 | break; |
318 | 328 | case '_wpg': // wikipage |
— | — | @@ -373,10 +383,12 @@ |
374 | 384 | $result[] = Title::newFromID($row->subject_id); |
375 | 385 | } |
376 | 386 | $db->freeResult($res); |
| 387 | + wfProfileOut("SMWSQLStore::getPropertySubjects (SMW)"); |
377 | 388 | return $result; |
378 | 389 | } |
379 | 390 | |
380 | 391 | function getAllPropertySubjects(Title $property, $requestoptions = NULL) { |
| 392 | + wfProfileIn("SMWSQLStore::getAllPropertySubjects (SMW)"); |
381 | 393 | $db =& wfGetDB( DB_SLAVE ); |
382 | 394 | $id = SMWDataValueFactory::getPropertyObjectTypeID($property); |
383 | 395 | switch ($id) { |
— | — | @@ -411,10 +423,12 @@ |
412 | 424 | $result[] = Title::newFromId($row->subject_id); |
413 | 425 | } |
414 | 426 | $db->freeResult($res); |
| 427 | + wfProfileOut("SMWSQLStore::getAllPropertySubjects (SMW)"); |
415 | 428 | return $result; |
416 | 429 | } |
417 | 430 | |
418 | 431 | function getProperties(Title $subject, $requestoptions = NULL) { |
| 432 | + wfProfileIn("SMWSQLStore::getProperties (SMW)"); |
419 | 433 | $db =& wfGetDB( DB_SLAVE ); |
420 | 434 | $sql = 'subject_id=' . $db->addQuotes($subject->getArticleID()) . $this->getSQLConditions($requestoptions,'attribute_title','attribute_title'); |
421 | 435 | |
— | — | @@ -458,11 +472,12 @@ |
459 | 473 | } |
460 | 474 | } |
461 | 475 | $db->freeResult($res); |
462 | | - |
| 476 | + wfProfileOut("SMWSQLStore::getProperties (SMW)"); |
463 | 477 | return $result; |
464 | 478 | } |
465 | 479 | |
466 | 480 | function getInProperties(SMWDataValue $value, $requestoptions = NULL) { |
| 481 | + wfProfileIn("SMWSQLStore::getInProperties (SMW)"); |
467 | 482 | $db =& wfGetDB( DB_SLAVE ); |
468 | 483 | $result = array(); |
469 | 484 | if ($value->getTypeID() == '_wpg') { |
— | — | @@ -478,12 +493,14 @@ |
479 | 494 | } |
480 | 495 | $db->freeResult($res); |
481 | 496 | } |
| 497 | + wfProfileOut("SMWSQLStore::getInProperties (SMW)"); |
482 | 498 | return $result; |
483 | 499 | } |
484 | 500 | |
485 | 501 | ///// Writing methods ///// |
486 | 502 | |
487 | 503 | function deleteSubject(Title $subject) { |
| 504 | + wfProfileIn("SMWSQLStore::deleteSubjects (SMW)"); |
488 | 505 | $db =& wfGetDB( DB_MASTER ); |
489 | 506 | $db->delete('smw_relations', |
490 | 507 | array('subject_id' => $subject->getArticleID()), |
— | — | @@ -518,9 +535,11 @@ |
519 | 536 | array('subject_title' => $subject->getDBKey()), |
520 | 537 | 'SMW::deleteSubject::Subprops'); |
521 | 538 | } |
| 539 | + wfProfileOut("SMWSQLStore::deleteSubjects (SMW)"); |
522 | 540 | } |
523 | 541 | |
524 | 542 | function updateData(SMWSemanticData $data) { |
| 543 | + wfProfileOut("SMWSQLStore::updateData (SMW)"); |
525 | 544 | $db =& wfGetDB( DB_MASTER ); |
526 | 545 | $subject = $data->getSubject(); |
527 | 546 | $this->deleteSubject($subject); |
— | — | @@ -683,9 +702,11 @@ |
684 | 703 | if (count($up_nary_longstrings) > 0) { |
685 | 704 | $db->insert( 'smw_nary_longstrings', $up_nary_longstrings, 'SMW::updateNAryLongData'); |
686 | 705 | } |
| 706 | + wfProfileOut("SMWSQLStore::updateData (SMW)"); |
687 | 707 | } |
688 | 708 | |
689 | 709 | function changeTitle(Title $oldtitle, Title $newtitle, $keepid = true) { |
| 710 | + wfProfileIn("SMWSQLStore::changeTitle (SMW)"); |
690 | 711 | $db =& wfGetDB( DB_MASTER ); |
691 | 712 | |
692 | 713 | $cond_array = array( 'subject_title' => $oldtitle->getDBkey(), |
— | — | @@ -726,6 +747,7 @@ |
727 | 748 | $db->delete('smw_subprops', array('subject_title' => $oldtitle->getDBKey()), 'SMW::changeTitle'); |
728 | 749 | } |
729 | 750 | } |
| 751 | + wfProfileOut("SMWSQLStore::changeTitle (SMW)"); |
730 | 752 | } |
731 | 753 | |
732 | 754 | ///// Query answering ///// |
— | — | @@ -737,6 +759,7 @@ |
738 | 760 | * NOTE: we do not support category wildcards, as they have no useful semantics in OWL/RDFS/LP/whatever |
739 | 761 | */ |
740 | 762 | function getQueryResult(SMWQuery $query) { |
| 763 | + wfProfileIn('SMWSQLStore::getQueryResult (SMW)'); |
741 | 764 | global $smwgQSortingSupport; |
742 | 765 | |
743 | 766 | $db =& wfGetDB( DB_SLAVE ); |
— | — | @@ -774,7 +797,10 @@ |
775 | 798 | 'SMW::getQueryResult', |
776 | 799 | $sql_options ); |
777 | 800 | $row = $db->fetchObject($res); |
778 | | - return $row->count; |
| 801 | + $count = $row->count; |
| 802 | + $db->freeResult($res); |
| 803 | + wfProfileOut('SMWSQLStore::getQueryResult (SMW)'); |
| 804 | + return $count; |
779 | 805 | // TODO: report query errors? |
780 | 806 | } elseif ($query->querymode == SMWQuery::MODE_DEBUG) { /// TODO: internationalise |
781 | 807 | list( $startOpts, $useIndex, $tailOpts ) = $db->makeSelectOptions( $sql_options ); |
— | — | @@ -804,6 +830,7 @@ |
805 | 831 | $result .= '<br />'; |
806 | 832 | } |
807 | 833 | $result .= '</div>'; |
| 834 | + wfProfileOut('SMWSQLStore::getQueryResult (SMW)'); |
808 | 835 | return $result; |
809 | 836 | } // else: continue |
810 | 837 | |
— | — | @@ -847,13 +874,14 @@ |
848 | 875 | } |
849 | 876 | $result->addRow($row); |
850 | 877 | } |
851 | | - |
| 878 | + wfProfileOut('SMWSQLStore::getQueryResult (SMW)'); |
852 | 879 | return $result; |
853 | 880 | } |
854 | 881 | |
855 | 882 | ///// Special page functions ///// |
856 | 883 | |
857 | 884 | function getPropertiesSpecial($requestoptions = NULL) { |
| 885 | + wfProfileIn("SMWSQLStore::getPropertiesSpecial (SMW)"); |
858 | 886 | $db =& wfGetDB( DB_SLAVE ); |
859 | 887 | $options = ' ORDER BY title'; |
860 | 888 | if ($requestoptions->limit >= 0) { |
— | — | @@ -877,10 +905,12 @@ |
878 | 906 | $result[] = array($title, $row->count); |
879 | 907 | } |
880 | 908 | $db->freeResult($res); |
| 909 | + wfProfileOut("SMWSQLStore::getPropertiesSpecial (SMW)"); |
881 | 910 | return $result; |
882 | 911 | } |
883 | 912 | |
884 | 913 | function getUnusedPropertiesSpecial($requestoptions = NULL) { |
| 914 | + wfProfileIn("SMWSQLStore::getUnusedPropertiesSpecial (SMW)"); |
885 | 915 | /// FIXME filter out the builtin properties! |
886 | 916 | $db =& wfGetDB( DB_SLAVE ); |
887 | 917 | $options = ' ORDER BY page_title'; |
— | — | @@ -905,10 +935,12 @@ |
906 | 936 | while($row = $db->fetchObject($res)) { |
907 | 937 | $result[] = Title::newFromText($row->page_title, SMW_NS_PROPERTY); |
908 | 938 | } |
| 939 | + wfProfileOut("SMWSQLStore::getUnusedPropertiesSpecial (SMW)"); |
909 | 940 | return $result; |
910 | 941 | } |
911 | 942 | |
912 | 943 | function getWantedPropertiesSpecial($requestoptions = NULL) { |
| 944 | + wfProfileIn("SMWSQLStore::getWantedPropertiesSpecial (SMW)"); |
913 | 945 | $db =& wfGetDB( DB_SLAVE ); |
914 | 946 | $options = ' ORDER BY count DESC'; |
915 | 947 | if ($requestoptions->limit >= 0) { |
— | — | @@ -926,10 +958,12 @@ |
927 | 959 | $title = Title::newFromText($row->title, SMW_NS_PROPERTY); |
928 | 960 | $result[] = array($title, $row->count); |
929 | 961 | } |
| 962 | + wfProfileOut("SMWSQLStore::getWantedPropertiesSpecial (SMW)"); |
930 | 963 | return $result; |
931 | 964 | } |
932 | 965 | |
933 | 966 | function getStatistics() { |
| 967 | + wfProfileIn("SMWSQLStore::getStatistics (SMW)"); |
934 | 968 | $db =& wfGetDB( DB_SLAVE ); |
935 | 969 | $result = array(); |
936 | 970 | extract( $db->tableNames('smw_relations', 'smw_attributes', 'smw_longstrings', 'smw_nary', 'smw_specialprops') ); |
— | — | @@ -975,6 +1009,7 @@ |
976 | 1010 | $result['DECLPROPS'] = $row->count; |
977 | 1011 | $db->freeResult( $res ); |
978 | 1012 | |
| 1013 | + wfProfileOut("SMWSQLStore::getStatistics (SMW)"); |
979 | 1014 | return $result; |
980 | 1015 | } |
981 | 1016 | |
— | — | @@ -1183,6 +1218,7 @@ |
1184 | 1219 | * wrt. the category table. |
1185 | 1220 | */ |
1186 | 1221 | protected function getCategoryTable($catname, &$db) { |
| 1222 | + wfProfileIn("SMWSQLStore::getCategoryTable (SMW)"); |
1187 | 1223 | global $wgDBname, $smwgQSubcategoryDepth; |
1188 | 1224 | |
1189 | 1225 | $tablename = 'cats' . SMWSQLStore::$m_tablenum++; |
— | — | @@ -1195,6 +1231,7 @@ |
1196 | 1232 | SMWSQLStore::$m_categorytables[$catname] . |
1197 | 1233 | '.title FROM ' . SMWSQLStore::$m_categorytables[$catname], |
1198 | 1234 | 'SMW::getCategoryTable'); |
| 1235 | + wfProfileOut("SMWSQLStore::getCategoryTable (SMW)"); |
1199 | 1236 | return $tablename; |
1200 | 1237 | } |
1201 | 1238 | |
— | — | @@ -1234,6 +1271,7 @@ |
1235 | 1272 | SMWSQLStore::$m_categorytables[$catname] = $tablename; |
1236 | 1273 | $db->query('DROP TABLE smw_newcats', 'SMW::getCategoryTable'); |
1237 | 1274 | $db->query('DROP TABLE smw_rescats', 'SMW::getCategoryTable'); |
| 1275 | + wfProfileOut("SMWSQLStore::getCategoryTable (SMW)"); |
1238 | 1276 | return $tablename; |
1239 | 1277 | } |
1240 | 1278 | |
— | — | @@ -1242,6 +1280,7 @@ |
1243 | 1281 | * wrt. the subproperty relation. |
1244 | 1282 | */ |
1245 | 1283 | protected function getPropertyTable($propname, &$db) { |
| 1284 | + wfProfileIn("SMWSQLStore::getPropertyTable (SMW)"); |
1246 | 1285 | global $wgDBname, $smwgQSubpropertyDepth; |
1247 | 1286 | |
1248 | 1287 | $tablename = 'prop' . SMWSQLStore::$m_tablenum++; |
— | — | @@ -1254,6 +1293,7 @@ |
1255 | 1294 | SMWSQLStore::$m_propertytables[$propname] . |
1256 | 1295 | '.title FROM ' . SMWSQLStore::$m_propertytables[$propname], |
1257 | 1296 | 'SMW::getPropertyTable'); |
| 1297 | + wfProfileOut("SMWSQLStore::getPropertyTable (SMW)"); |
1258 | 1298 | return $tablename; |
1259 | 1299 | } |
1260 | 1300 | |
— | — | @@ -1290,6 +1330,7 @@ |
1291 | 1331 | SMWSQLStore::$m_propertytables[$propname] = $tablename; |
1292 | 1332 | $db->query('DROP TABLE smw_new', 'SMW::getPropertyTable'); |
1293 | 1333 | $db->query('DROP TABLE smw_res', 'SMW::getPropertyTable'); |
| 1334 | + wfProfileOut("SMWSQLStore::getPropertyTable (SMW)"); |
1294 | 1335 | return $tablename; |
1295 | 1336 | } |
1296 | 1337 | |