Revert "Improve .Content vs shortcodes"

This reverts commit e590cc26eb.
This commit is contained in:
Bjørn Erik Pedersen 2018-04-19 17:40:57 +02:00
parent d6982ac0ac
commit d6a2024e6b
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F
5 changed files with 26 additions and 77 deletions

View file

@ -559,83 +559,38 @@ func (h *HugoSites) setupTranslations() {
} }
} }
type pagesRenderPreparer struct {
numWorkers int
s *Site
cfg *BuildCfg
wg *sync.WaitGroup
pages chan *Page
}
func newStartedRenderPreparator(s *Site, cfg *BuildCfg) *pagesRenderPreparer {
numWorkers := getGoMaxProcs() * 4
pp := &pagesRenderPreparer{
s: s,
cfg: cfg,
numWorkers: numWorkers,
wg: &sync.WaitGroup{},
pages: make(chan *Page),
}
pp.start()
return pp
}
func (pp *pagesRenderPreparer) start() {
for i := 0; i < pp.numWorkers; i++ {
pp.wg.Add(1)
go func() {
defer pp.wg.Done()
for p := range pp.pages {
if err := p.prepareForRender(pp.cfg); err != nil {
pp.s.Log.ERROR.Printf("Failed to prepare page %q for render: %s", p.BaseFileName(), err)
}
}
}()
}
}
func (pp *pagesRenderPreparer) add(p *Page) {
pp.pages <- p
}
func (pp *pagesRenderPreparer) done() {
close(pp.pages)
pp.wg.Wait()
}
func (s *Site) preparePagesForRender(cfg *BuildCfg) { func (s *Site) preparePagesForRender(cfg *BuildCfg) {
// For the content from other pages in shortcodes there are some chicken and pageChan := make(chan *Page)
// egg dependencies that is hard to get around. But we can improve on this wg := &sync.WaitGroup{}
// by preparing the pages in a certain order.
// So the headless pages goes first. These are typically collection of numWorkers := getGoMaxProcs() * 4
// pages and images etc. used by others.
batch := newStartedRenderPreparator(s, cfg) for i := 0; i < numWorkers; i++ {
for _, p := range s.headlessPages { wg.Add(1)
batch.add(p) go func(pages <-chan *Page, wg *sync.WaitGroup) {
defer wg.Done()
for p := range pages {
if err := p.prepareForRender(cfg); err != nil {
s.Log.ERROR.Printf("Failed to prepare page %q for render: %s", p.BaseFileName(), err)
}
}
}(pageChan, wg)
} }
batch.done()
// Then the rest in the following order:
order := []bundleDirType{bundleLeaf, bundleNot, bundleBranch}
for _, tp := range order {
batch = newStartedRenderPreparator(s, cfg)
for _, p := range s.Pages { for _, p := range s.Pages {
// sanity check pageChan <- p
if p.bundleType < 0 || p.bundleType > bundleBranch {
panic("unknown bundle type")
} }
if p.bundleType == tp {
batch.add(p) for _, p := range s.headlessPages {
} pageChan <- p
}
batch.done()
} }
close(pageChan)
wg.Wait()
} }
// Pages returns all pages for all sites. // Pages returns all pages for all sites.

View file

@ -224,7 +224,6 @@ func (h *HugoSites) render(config *BuildCfg) error {
s.initRenderFormats() s.initRenderFormats()
for i, rf := range s.renderFormats { for i, rf := range s.renderFormats {
s.rc = &siteRenderingContext{Format: rf} s.rc = &siteRenderingContext{Format: rf}
s.preparePagesForRender(config) s.preparePagesForRender(config)
if !config.SkipRender { if !config.SkipRender {

View file

@ -243,8 +243,6 @@ type Page struct {
// 3. But you can get it via .Site.GetPage // 3. But you can get it via .Site.GetPage
headless bool headless bool
bundleType bundleDirType
layoutDescriptor output.LayoutDescriptor layoutDescriptor output.LayoutDescriptor
scratch *Scratch scratch *Scratch

View file

@ -218,8 +218,6 @@ func (c *contentHandlers) parsePage(h contentHandler) contentHandler {
ctx.currentPage = p ctx.currentPage = p
if ctx.bundle != nil { if ctx.bundle != nil {
p.bundleType = ctx.bundle.tp
// Add the bundled files // Add the bundled files
for _, fi := range ctx.bundle.resources { for _, fi := range ctx.bundle.resources {
childCtx := ctx.childCtx(fi) childCtx := ctx.childCtx(fi)

View file

@ -1865,7 +1865,6 @@ func getGoMaxProcs() int {
func (s *Site) newNodePage(typ string, sections ...string) *Page { func (s *Site) newNodePage(typ string, sections ...string) *Page {
p := &Page{ p := &Page{
bundleType: bundleBranch,
language: s.Language, language: s.Language,
pageInit: &pageInit{}, pageInit: &pageInit{},
Kind: typ, Kind: typ,