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

Build: use partialCached #1951

Open
wants to merge 2 commits into
base: gh-pages
Choose a base branch
from

Conversation

dotnetCarpenter
Copy link
Contributor

Changes

  • footer.html
  • monitor.html

Context

This gives a 11% (9 seconds) speedup, when building the site, on my system.

@@ -165,7 +165,7 @@ <h1 data-pagefind-meta="title">About{{ if (isset .Params "subtitle") }} - {{ .Pa
{{ end }}
</div>
</div>
{{ partial "footer.html" . }}
{{ partialCached "footer.html" . }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that this would break the /search page, as there is a line in footer.html that is contingent on the current page section.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dotnetCarpenter could you have a look whether the search page renders correctly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dotnetCarpenter I had a look, and it does not look good:

ca70cdd917e0fef93cec35d593cd9e12db7a5ab7

In my hands, you need this to fix it:

Suggested change
{{ partialCached "footer.html" . }}
{{ if eq (.Scratch.Get "section") "search" }}
{{ partial "footer.html" . }}
{{ else }}
{{ partialCached "footer.html" . }}
{{ end }}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dscho I'll take a look :)

@dscho
Copy link
Member

dscho commented Feb 19, 2025

That is a nice improvement! If we can make it work even with the search page (think: https://git-scm.com/search/results?search=site&language=en), I am all for it!

@dotnetCarpenter
Copy link
Contributor Author

@dscho it seems that varying by "section" works. That is, create a new cached version for each section. But now I'm not seeing any speed improvement in build time. I think, without any measurable performance boost in build time, this PR only complicates matters and should be closed.

I'm extremely new to hugo, so there might be something worth salvaging here but I don't think so.

+ footer.html
+ monitor.html

This gives a 11% (9 seconds) speedup, when building the site,
on my system.
Create a new cached footer for each section set in baseof.html.
This makes sure that pagefind/pagefind-ui.js is included if the
section is "search".
@dotnetCarpenter
Copy link
Contributor Author

All tests pass with #1955 on Kali linux with:

bun script/serve-public.js
npx playwright install firefox
npx playwright test --project=firefox

@dscho
Copy link
Member

dscho commented Feb 25, 2025

npx playwright test --project=firefox

I believe that this tests https://git-scm.com/ by default. To test the local site, you need to set PLAYWRIGHT_TEST_URL=http://localhost:5000/ before running Playwright (and then you do not need to start the server manually).

@dscho
Copy link
Member

dscho commented Feb 25, 2025

@dscho it seems that varying by "section" works. That is, create a new cached version for each section. But now I'm not seeing any speed improvement in build time.

Right. A much better idea might be to move this line from footer.html into the baseof.html layout, just before the line that includes the footer in the part that is relevant to the search page:

{{ if eq (.Scratch.Get "section") "search" }}<script src="{{ relURL "pagefind/pagefind-ui.js" }}"></script>{{ end }}

Since this is the only conditional code in footer.html (and there is no conditional code in monitor.html), this should salvage the improved build time again.

For what it's worth, I believe that I did things quite sub-optimally with Hugo; It feels as if the proper way would not end up with a huge baseof.html layout including lots of conditionals...

@dotnetCarpenter
Copy link
Contributor Author

dotnetCarpenter commented Feb 25, 2025

I ran the test with PLAYWRIGHT_TEST_URL=http://localhost:5000/ and got an error that looks like the expectation is slightly off. It's missing a trailing /.

Error: Timed out 5000ms waiting for expect(locator).toHaveAttribute(expected)

Locator: locator('#search-results').getByRole('link').first()
Expected pattern: /\/docs\/git-add\/fr(\.html)?$/
Received string:  "/docs/git-add/fr/"
Call log:
  - expect.toHaveAttribute with timeout 5000ms
  - waiting for locator('#search-results').getByRole('link').first()
    5 × locator resolved to <a href="/docs/git-add/fr/">git-add</a>
      - unexpected value "/docs/git-add/fr/"


  138 |   await searchBox.fill('add')
  139 |   await searchBox.press('Shift')
> 140 |   await expect(searchResults.getByRole("link").nth(0)).toHaveAttribute('href', /\/docs\/git-add\/fr(\.html)?$/)
      |                                                        ^
  141 |
  142 |   // pressing the Enter key should navigate to the full search results page
  143 |   await searchBox.press('Enter')
    at /home/dotnet/projects/opensource/git-scm.com/tests/git-scm.spec.js:140:56

Perhaps /\/docs\/git-add\/fr(\.html|\/)?$/ would be better, if .html is a possible solution. What are the correct possibilities?

103-1-failure

EDIT

Hmm for some reason there are two versions of each result. One with a trailing / and one without. I get the same result with PR #1955.

@dscho
Copy link
Member

dscho commented Feb 27, 2025

Expected pattern: //docs/git-add/fr(.html)?$/
Received string: "/docs/git-add/fr/"

Hmm. The received string seems bogus: If you call curl https://git-scm.com/docs/git-add/fr/ you will see that it wants to redirect to https://git-scm.com/docs/git-add/fr:

<html lang="en">
 <head>
  <meta charset="utf-8">
  <title>Redirecting&hellip;</title>
  <link rel="canonical" href="https://git-scm.com/docs/git-add/fr">
  <meta http-equiv="refresh" content="0; url=https://git-scm.com/docs/git-add/fr">
  <meta name="robots" content="noindex">
 </head>
 <body>
  <script>window.location.replace(document.querySelector("link[rel='canonical']").href + window.location.search + window.location.hash)</script>
  <h1>Redirecting&hellip;</h1>
  <a href="https://git-scm.com/docs/git-add/fr">Click here if you are not redirected.</a>
 </body>
</html>

So why does your Playwright instance not follow that redirect?

@dscho
Copy link
Member

dscho commented Feb 27, 2025

So why does your Playwright instance not follow that redirect?

Oh, did you perchance turn off "ugly" URLs?

@dscho
Copy link
Member

dscho commented Mar 2, 2025

@dscho it seems that varying by "section" works. That is, create a new cached version for each section. But now I'm not seeing any speed improvement in build time.

Right. A much better idea might be to move this line from footer.html into the baseof.html layout, just before the line that includes the footer in the part that is relevant to the search page:

{{ if eq (.Scratch.Get "section") "search" }}<script src="{{ relURL "pagefind/pagefind-ui.js" }}"></script>{{ end }}

Since this is the only conditional code in footer.html (and there is no conditional code in monitor.html), this should salvage the improved build time again.

For what it's worth, I believe that I did things quite sub-optimally with Hugo; It feels as if the proper way would not end up with a huge baseof.html layout including lots of conditionals...

How about rebasing on top of gh-pages (which has the additional Playwright test of the search results page) and playing with this idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants