r26944 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r26943‎ | r26944 | r26945 >
Date:13:26, 25 October 2007
Author:vrandezo
Status:old
Tags:
Comment:
Added delay to dumpRDF script. Added profiling to export.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/maintenance/SMW_dumpRDF.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/ExportRDF/SMW_SpecialExportRDF.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/maintenance/SMW_dumpRDF.php
@@ -10,11 +10,14 @@
1111 * --properties only do properties
1212 * --types only do types
1313 * --individuals only do pages that are no categories, properties, or types
 14+ * -d <delay> slows down the export in order to stress the server less,
 15+ * sleeping for <delay> milliseconds every now and then
 16+ * -e <each> after how many exported entities should the server take a nap?
1417 *
1518 * @author Markus Krötzsch
1619 */
1720
18 -$optionsWithArgs = array( 'o' ); // -o <output file>
 21+$optionsWithArgs = array( 'o', 'd', 'e' );
1922
2023 require_once( 'commandLine.inc' );
2124 require_once( "$IP/extensions/SemanticMediaWiki/specials/ExportRDF/SMW_SpecialExportRDF.php");
@@ -24,7 +27,18 @@
2528 } else {
2629 $outfile = false;
2730 }
 31+if ( !empty( $options['d'] ) ) {
 32+ $delay = intval($options['d']) * 1000;
 33+} else {
 34+ $delay = 0;
 35+}
 36+if ( !empty( $options['e'] ) ) {
 37+ $delayeach = intval($options['e']);
 38+} else {
 39+ $delayeach = ( $delay === 0 ) ? 0 : 1;
 40+}
2841
 42+
2943 if ( array_key_exists( 'categories' , $options ) ) {
3044 $export_ns = NS_CATEGORY;
3145 } elseif ( array_key_exists( 'properties' , $options ) ) {
@@ -38,5 +52,5 @@
3953 }
4054
4155 $exRDF = new ExportRDF();
42 -$exRDF->printAll($outfile, $export_ns);
 56+$exRDF->printAll($outfile, $export_ns, $delay, $delayeach);
4357
Index: trunk/extensions/SemanticMediaWiki/specials/ExportRDF/SMW_SpecialExportRDF.php
@@ -372,6 +372,9 @@
373373 * properties are exported as well. Enables "browsable RDF."
374374 */
375375 public function printPages($pages, $recursion = 1, $backlinks = true) {
 376+
 377+ wfProfileIn("RDF::PrintPages");
 378+
376379 $this->store = &smwfGetStore();
377380 $this->pre_ns_buffer = '';
378381 $this->post_ns_buffer = '';
@@ -381,6 +384,7 @@
382385 $this->printHeader(); // also inits global namespaces
383386 $linkCache =& LinkCache::singleton();
384387
 388+ wfProfileIn("RDF::PrintPages::PrepareQueue");
385389 // transform pages into queued export titles
386390 $cur_queue = array();
387391 foreach ($pages as $page) {
@@ -389,12 +393,15 @@
390394 $et = new SMWExportTitle($title, $this);
391395 $cur_queue[$title->getPrefixedURL() . ' '] = $et; // " " is the modifier separator
392396 }
 397+ wfProfileOut("RDF::PrintPages::PrepareQueue");
393398
394399 while (count($cur_queue) > 0) {
395400 // first, print all selected pages
396401 foreach ( $cur_queue as $et) {
 402+ wfProfileIn("RDF::PrintPages::PrintOne");
397403 $this->printTriples($et);
398404 $this->markAsDone($et);
 405+ wfProfileOut("RDF::PrintPages::PrintOne");
399406
400407 // prepare array for next iteration
401408 $cur_queue = array();
@@ -404,6 +411,7 @@
405412 }
406413 // possibly add backlinks
407414 if ($backlinks === true) {
 415+ wfProfileIn("RDF::PrintPages::GetBacklinks");
408416 $inRels = $this->store->getInProperties( $et->value );
409417 foreach ($inRels as $inRel) {
410418 $inSubs = $this->store->getPropertySubjects( $inRel, $et->value );
@@ -424,12 +432,14 @@
425433 }
426434 }
427435 if ( 0 == $recursion ) $backlinks = false; // do not recurse through backlinks either
 436+ wfProfileOut("RDF::PrintPages::GetBacklinks");
428437 }
429438 if ($this->delay_flush > 0) $this->delay_flush--;
430439 }
431440 $linkCache->clear();
432441 }
433442
 443+ wfProfileIn("RDF::PrintPages::Auxilliary");
434444 // if pages are not processed recursively, print mentioned declarations
435445 if (!empty($this->element_queue)) {
436446 if ( '' != $this->pre_ns_buffer ) {
@@ -442,16 +452,19 @@
443453 $this->printTriples($et,false);
444454 }
445455 }
 456+ wfProfileOut("RDF::PrintPages::Auxilliary");
446457
447458 $this->printFooter();
448459 $this->flushBuffers(true);
 460+
 461+ wfProfileOut("RDF::PrintPages");
449462 }
450463
451464 /**
452465 * This function prints RDF for *all* pages within the wiki, and for all
453466 * elements that are referred to in the exported RDF.
454467 */
455 - public function printAll($outfile, $ns_restriction = false) {
 468+ public function printAll($outfile, $ns_restriction = false, $delay, $delayeach) {
456469 global $smwgNamespacesWithSemanticLinks;
457470 $linkCache =& LinkCache::singleton();
458471
@@ -480,6 +493,7 @@
481494
482495 $a_count = 0; $d_count = 0; //DEBUG
483496
 497+ $delaycount = $delayeach;
484498 for ($id = $start; $id <= $end; $id++) {
485499 $title = Title::newFromID($id);
486500 if ( ($title === NULL) || !smwfIsSemanticsProcessed($title->getNamespace()) ) continue;
@@ -509,6 +523,11 @@
510524 // want to export now is a potential memory leak
511525 }
512526 }
 527+ // sleep each $delaycount for $delay ms to be nice to the server
 528+ if (($delaycount-- < 0) && ($delayeach != 0)) {
 529+ usleep($delay);
 530+ $delaycount = $delayeach;
 531+ }
513532 }
514533 if ($outfile !== false) { // flush buffer
515534 fwrite($file, $this->post_ns_buffer);

Status & tagging log