shithub: hugo

Download patch

ref: bcc42c0549263681ef9eada21a9fc4eb2d8ff055
parent: f3aa93fa484628316105dac6bfe4cea4b6992a3b
author: Steve Francia <[email protected]>
date: Mon Dec 21 14:47:48 EST 2015

Separate reading source and processing source operations

--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -509,6 +509,7 @@
 }
 
 func (s *Site) Process() (err error) {
+	s.timerStep("Go initialization")
 	if err = s.initialize(); err != nil {
 		return
 	}
@@ -535,7 +536,6 @@
 		return
 	}
 	s.setupPrevNext()
-	s.timerStep("import pages")
 	if err = s.BuildSiteMeta(); err != nil {
 		return
 	}
@@ -688,21 +688,19 @@
 	err  error
 }
 
-func (s *Site) CreatePages() error {
+func (s *Site) ReadPagesFromSource() chan error {
 	if s.Source == nil {
 		panic(fmt.Sprintf("s.Source not set %s", s.absContentDir()))
 	}
+
 	if len(s.Source.Files()) < 1 {
 		return nil
 	}
 
 	files := s.Source.Files()
-
 	results := make(chan HandledResult)
 	filechan := make(chan *source.File)
-
 	procs := getGoMaxProcs()
-
 	wg := &sync.WaitGroup{}
 
 	wg.Add(procs * 4)
@@ -721,19 +719,20 @@
 	}
 
 	close(filechan)
-
 	wg.Wait()
-
 	close(results)
 
-	readErrs := <-errs
+	return errs
+}
 
-	results = make(chan HandledResult)
+func (s *Site) ConvertSource() chan error {
+	errs := make(chan error)
+	results := make(chan HandledResult)
 	pageChan := make(chan *Page)
 	fileConvChan := make(chan *source.File)
+	procs := getGoMaxProcs()
+	wg := &sync.WaitGroup{}
 
-	wg = &sync.WaitGroup{}
-
 	wg.Add(2 * procs * 4)
 	for i := 0; i < procs*4; i++ {
 		go fileConverter(s, fileConvChan, results, wg)
@@ -752,13 +751,19 @@
 
 	close(pageChan)
 	close(fileConvChan)
-
 	wg.Wait()
-
 	close(results)
 
-	renderErrs := <-errs
+	return errs
+}
 
+func (s *Site) CreatePages() error {
+	readErrs := <-s.ReadPagesFromSource()
+	s.timerStep("read pages from source")
+
+	renderErrs := <-s.ConvertSource()
+	s.timerStep("convert source")
+
 	if renderErrs == nil && readErrs == nil {
 		return nil
 	}
@@ -768,6 +773,7 @@
 	if readErrs == nil {
 		return renderErrs
 	}
+
 	return fmt.Errorf("%s\n%s", readErrs, renderErrs)
 }