Skip to content

Commit 1133850

Browse files
committed
Emit whole <page> chunks from XML creator, giving a 50% speed increase
1 parent b685045 commit 1133850

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

main.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func main() {
7272
xmlCreator := NewMWXMLCreator()
7373
pipeRunner.AddProcess(xmlCreator)
7474

75-
printer := NewLinePrinter()
75+
printer := NewStringPrinter()
7676
pipeRunner.AddProcess(printer)
7777

7878
// ------------------------------------------
@@ -92,7 +92,7 @@ func main() {
9292

9393
triplesToWikiConverter.OutPage = xmlCreator.InWikiPage
9494

95-
xmlCreator.OutLine = printer.In
95+
xmlCreator.Out = printer.In
9696

9797
// ------------------------------------------
9898
// Send in-data and run
@@ -476,13 +476,13 @@ func (p *TripleAggregateToWikiPageConverter) convertUriToWikiTitle(uri string, u
476476

477477
type MWXMLCreator struct {
478478
InWikiPage chan *WikiPage
479-
OutLine chan string
479+
Out chan string
480480
}
481481

482482
func NewMWXMLCreator() *MWXMLCreator {
483483
return &MWXMLCreator{
484484
InWikiPage: make(chan *WikiPage, BUFSIZE),
485-
OutLine: make(chan string, BUFSIZE),
485+
Out: make(chan string, BUFSIZE),
486486
}
487487
}
488488

@@ -511,9 +511,9 @@ var pageTypeToMWNamespace = map[int]int{
511511
}
512512

513513
func (p *MWXMLCreator) Run() {
514-
defer close(p.OutLine)
514+
defer close(p.Out)
515515

516-
p.OutLine <- "<mediawiki>"
516+
p.Out <- "<mediawiki>\n"
517517

518518
for page := range p.InWikiPage {
519519

@@ -528,12 +528,12 @@ func (p *MWXMLCreator) Run() {
528528
}
529529

530530
xmlData := fmt.Sprintf(wikiXmlTpl, page.Title, pageTypeToMWNamespace[page.Type], time.Now().Format("2006-01-02T15:04:05Z"), wikiText)
531-
for _, line := range str.Split(xmlData, "\n") {
532-
p.OutLine <- line
533-
}
531+
532+
// Print out the generated XML one line at a time
533+
p.Out <- xmlData
534534
}
535535

536-
p.OutLine <- "</mediawiki>"
536+
p.Out <- "</mediawiki>\n"
537537
}
538538

539539
// --------------------------------------------------------------------------------
@@ -628,22 +628,22 @@ func (p *WikiPagePrinter) Run() {
628628
}
629629

630630
// --------------------------------------------------------------------------------
631-
// Line Printer
631+
// String Printer
632632
// --------------------------------------------------------------------------------
633633

634-
type LinePrinter struct {
634+
type StringPrinter struct {
635635
In chan string
636636
}
637637

638-
func NewLinePrinter() *LinePrinter {
639-
return &LinePrinter{
638+
func NewStringPrinter() *StringPrinter {
639+
return &StringPrinter{
640640
In: make(chan string, BUFSIZE),
641641
}
642642
}
643643

644-
func (p *LinePrinter) Run() {
645-
for line := range p.In {
646-
fmt.Println(line)
644+
func (p *StringPrinter) Run() {
645+
for s := range p.In {
646+
fmt.Print(s)
647647
}
648648
}
649649

0 commit comments

Comments
 (0)