hugolib: Avoid scanning entire site to find the home

See #4447
This commit is contained in:
Bjørn Erik Pedersen 2018-02-25 10:50:44 +01:00
parent 00868081f6
commit e39797fa72
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F
2 changed files with 10 additions and 7 deletions

View file

@ -152,6 +152,15 @@ func (*PageCollections) findPagesByKindIn(kind string, inPages Pages) Pages {
return pages
}
func (*PageCollections) findFirstPageByKindIn(kind string, inPages Pages) *Page {
for _, p := range inPages {
if p.Kind == kind {
return p
}
}
return nil
}
func (*PageCollections) findPagesByKindNotIn(kind string, inPages Pages) Pages {
var pages Pages
for _, p := range inPages {

View file

@ -161,18 +161,12 @@ func (s *Site) assembleSections() Pages {
)
var (
home *Page
inPages = radix.New().Txn()
inSections = radix.New().Txn()
undecided Pages
)
homes := s.findPagesByKind(KindHome)
if len(homes) == 1 {
home = homes[0]
} else if len(homes) > 1 {
panic("Too many homes")
}
home := s.findFirstPageByKindIn(KindHome, s.Pages)
for i, p := range s.Pages {
if p.Kind != KindPage {