Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up GetPage #3504

Merged
merged 1 commit into from
May 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions hugolib/page_collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions hugolib/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -1906,8 +1906,11 @@ func (s *Site) Stats() {
// This will return nil when no page could be found.
//
// The valid page types are: home, section, taxonomy and taxonomyTerm
func (s *SiteInfo) GetPage(typ string, path ...string) *Page {
return s.getPage(typ, path...)
func (s *SiteInfo) GetPage(typ string, path ...string) (*Page, error) {
if typ == KindPage {
return nil, errors.New("GetPage not supported for regular pages")
}
return s.getPage(typ, path...), nil
}

func (s *Site) permalinkForOutputFormat(link string, f output.Format) (string, error) {
Expand Down