shithub: hugo

Download patch

ref: e39797fa720829dafd165aa25bfc2605700c38dc
parent: 00868081f624928d773a7b698654766f8cd70069
author: Bjørn Erik Pedersen <[email protected]>
date: Sun Feb 25 05:50:44 EST 2018

hugolib: Avoid scanning entire site to find the home

See #4447

--- a/hugolib/page_collections.go
+++ b/hugolib/page_collections.go
@@ -152,6 +152,15 @@
 	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 {
--- a/hugolib/site_sections.go
+++ b/hugolib/site_sections.go
@@ -161,18 +161,12 @@
 	)
 
 	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 {