r23852 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23851‎ | r23852 | r23853 >
Date:18:29, 7 July 2007
Author:mkroetzsch
Status:old
Tags:
Comment:
Use multi-row inserts; faster writing
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php
@@ -431,17 +431,23 @@
432432 $db =& wfGetDB( DB_MASTER );
433433 $subject = $data->getSubject();
434434 $this->deleteSubject($subject);
 435+
 436+ // do bulk updates:
 437+ $up_relations = array();
 438+ $up_attributes = array();
 439+ $up_longstrings = array();
 440+ $up_specials = array();
 441+
435442 // relations
436443 foreach($data->getRelations() as $relation) {
437444 foreach($data->getRelationObjects($relation) as $object) {
438 - $db->insert( $db->tableName('smw_relations'),
439 - array( 'subject_id' => $subject->getArticleID(),
 445+ $up_relations[] =
 446+ array( 'subject_id' => $subject->getArticleID(),
440447 'subject_namespace' => $subject->getNamespace(),
441448 'subject_title' => $subject->getDBkey(),
442449 'relation_title' => $relation->getDBkey(),
443450 'object_namespace' => $object->getNamespace(),
444 - 'object_title' => $object->getDBkey()),
445 - 'SMW::updateRelData');
 451+ 'object_title' => $object->getDBkey() );
446452 }
447453 }
448454
@@ -451,24 +457,22 @@
452458 foreach($attributeValueArray as $value) {
453459 if ($value->getXSDValue()!==false) {
454460 if ($value->getTypeID() !== 'text') {
455 - $db->insert( $db->tableName('smw_attributes'),
456 - array( 'subject_id' => $subject->getArticleID(),
 461+ $up_attributes[] =
 462+ array( 'subject_id' => $subject->getArticleID(),
457463 'subject_namespace' => $subject->getNamespace(),
458464 'subject_title' => $subject->getDBkey(),
459465 'attribute_title' => $attribute->getDBkey(),
460466 'value_unit' => $value->getUnit(),
461467 'value_datatype' => $value->getTypeID(),
462468 'value_xsd' => $value->getXSDValue(),
463 - 'value_num' => $value->getNumericValue()),
464 - 'SMW::updateAttData');
 469+ 'value_num' => $value->getNumericValue() );
465470 } else {
466 - $db->insert( $db->tableName('smw_longstrings'),
467 - array( 'subject_id' => $subject->getArticleID(),
 471+ $up_longstrings[] =
 472+ array( 'subject_id' => $subject->getArticleID(),
468473 'subject_namespace' => $subject->getNamespace(),
469474 'subject_title' => $subject->getDBkey(),
470475 'attribute_title' => $attribute->getDBkey(),
471 - 'value_blob' => $value->getXSDValue()),
472 - 'SMW::updateAttDataLongString');
 476+ 'value_blob' => $value->getXSDValue() );
473477 }
474478 }
475479 }
@@ -494,15 +498,28 @@
495499 } else {
496500 $stringvalue = $value;
497501 }
498 - $db->insert( $db->tableName('smw_specialprops'),
499 - array('subject_id' => $subject->getArticleID(),
500 - 'subject_namespace' => $subject->getNamespace(),
501 - 'subject_title' => $subject->getDBkey(),
502 - 'property_id' => $special,
503 - 'value_string' => $stringvalue),
504 - 'SMW::updateSpecData');
 502+ $up_specials[] =
 503+ array('subject_id' => $subject->getArticleID(),
 504+ 'subject_namespace' => $subject->getNamespace(),
 505+ 'subject_title' => $subject->getDBkey(),
 506+ 'property_id' => $special,
 507+ 'value_string' => $stringvalue);
505508 }
506509 }
 510+
 511+ // write to DB:
 512+ if (count($up_relations) > 0) {
 513+ $db->insert( $db->tableName('smw_relations'), $up_relations, 'SMW::updateRelData');
 514+ }
 515+ if (count($up_attributes) > 0) {
 516+ $db->insert( $db->tableName('smw_attributes'), $up_attributes, 'SMW::updateAttData');
 517+ }
 518+ if (count($up_longstrings) > 0) {
 519+ $db->insert( $db->tableName('smw_longstrings'), $up_longstrings, 'SMW::updateLongData');
 520+ }
 521+ if (count($up_specials) > 0) {
 522+ $db->insert( $db->tableName('smw_specialprops'), $up_specials, 'SMW::updateSpecData');
 523+ }
507524 }
508525
509526 function changeTitle(Title $oldtitle, Title $newtitle, $keepid = true) {

Status & tagging log