hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit e39797fa720829dafd165aa25bfc2605700c38dc
parent 00868081f624928d773a7b698654766f8cd70069
Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date:   Sun, 25 Feb 2018 10:50:44 +0100

hugolib: Avoid scanning entire site to find the home

See #4447

Diffstat:
Mhugolib/page_collections.go | 9+++++++++
Mhugolib/site_sections.go | 8+-------
2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/hugolib/page_collections.go b/hugolib/page_collections.go
@@ -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 {
diff --git a/hugolib/site_sections.go b/hugolib/site_sections.go
@@ -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 {