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

Fix missing page data for alternative formats #9342

Merged
merged 2 commits into from
Jan 12, 2022

Commits on Jan 12, 2022

  1. Fix missing page data for alternative formats

    When a template calls the .Translations function and a
    Hugo environment is using multiple output formats,
    a template that calls methods like .Summary and .Len on
    each translation will unexpectedly show empty return
    values for these methods.
    
    This is because each pageOutput's ContentProvider is
    assigned to a page.NopPage in newPageOutput. When
    *HugoSites.render assigns pageContentOutputs to
    pageOutputs in *pageState.shiftToOutputFormat, it
    reuses pageContentOutputs from other pageOutputs,
    leaving some pageContentOutputs as NopPages. While this
    approach conserves resources, sometimes it means that
    a template will unexpectedly call a method on a
    pageContentOutput that is actually a NopPage.
    
    In the case of ContentProvider methods called on
    translations for alternative output formats, the methods
    were called on NopPages.
    
    This change introduces LazyContentProvider, which
    performs late initialization when one of its methods is
    called. This way, we can reuse content in "normal" cases
    but ensure that ContentProvider methods work as expected
    when a pageOutput is not assigned a pageContentOutput
    during the initial pre-render phase.
    
    Fixes gohugoio#8919
    ptgott authored and bep committed Jan 12, 2022
    Configuration menu
    Copy the full SHA
    25d645f View commit details
    Browse the repository at this point in the history
  2. Only create LazyContentProvider for the non-rendering Site

    Which saves a fair amound of allocations:
    
    ```
    gobench --package ./hugolib --bench "SiteNew/Regular_D" --base master
    ```
    
    Before:
    
    ```
    name                                  old time/op    new time/op    delta
    SiteNew/Regular_Deep_content_tree-10    40.7ms ± 3%    41.2ms ± 1%    ~     (p=0.343 n=4+4)
    
    name                                  old alloc/op   new alloc/op   delta
    SiteNew/Regular_Deep_content_tree-10    27.7MB ± 0%    28.8MB ± 0%  +3.76%  (p=0.029 n=4+4)
    
    name                                  old allocs/op  new allocs/op  delta
    SiteNew/Regular_Deep_content_tree-10      304k ± 0%      329k ± 0%  +8.07%  (p=0.029 n=4+4)
    ```
    
    After:
    
    ```
    name                                  old time/op    new time/op    delta
    SiteNew/Regular_Deep_content_tree-10    34.2ms ± 1%    34.7ms ± 1%    ~     (p=0.114 n=4+4)
    
    name                                  old alloc/op   new alloc/op   delta
    SiteNew/Regular_Deep_content_tree-10    27.7MB ± 0%    28.1MB ± 0%  +1.38%  (p=0.029 n=4+4)
    
    name                                  old allocs/op  new allocs/op  delta
    SiteNew/Regular_Deep_content_tree-10      304k ± 0%      314k ± 0%  +3.03%  (p=0.029 n=4+4)
    ```
    
    Updates gohugoio#8919
    bep committed Jan 12, 2022
    Configuration menu
    Copy the full SHA
    cdcd15b View commit details
    Browse the repository at this point in the history