mirror of
https://github.com/gohugoio/hugo.git
synced 2024-05-11 05:54:58 +00:00
hugolib: Speed up GetPage
When we know to look into the index pages collection, do that: ``` benchmark old ns/op new ns/op delta BenchmarkGetPage-4 51483 7072 -86.26% benchmark old allocs new allocs delta BenchmarkGetPage-4 71 71 +0.00% benchmark old bytes new bytes delta BenchmarkGetPage-4 2648 2648 +0.00% ``` This commit also returns an error if .Site.GetPage is called with the regular Page Kind, as that is currently not supported. Fixes #3503
This commit is contained in:
@@ -51,8 +51,8 @@ func newPageCollectionsFromPages(pages Pages) *PageCollections {
|
||||
return &PageCollections{rawAllPages: pages}
|
||||
}
|
||||
|
||||
func (c *PageCollections) getPage(typ string, path ...string) *Page {
|
||||
pages := c.findPagesByKindIn(typ, c.Pages)
|
||||
func (c *PageCollections) getFirstPageMatchIn(ps Pages, typ string, path ...string) *Page {
|
||||
pages := c.findPagesByKindIn(typ, ps)
|
||||
|
||||
if len(pages) == 0 {
|
||||
return nil
|
||||
@@ -78,6 +78,20 @@ func (c *PageCollections) getPage(typ string, path ...string) *Page {
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (c *PageCollections) getPage(typ string, path ...string) *Page {
|
||||
var pages Pages
|
||||
|
||||
if typ == KindPage {
|
||||
pages = c.RegularPages
|
||||
} else {
|
||||
pages = c.indexPages
|
||||
}
|
||||
|
||||
return c.getFirstPageMatchIn(pages, typ, path...)
|
||||
|
||||
}
|
||||
|
||||
func (*PageCollections) findPagesByKindIn(kind string, inPages Pages) Pages {
|
||||
|
||||
Reference in New Issue
Block a user