From 4ecf64c4565865c008feab7e2ba51e58963e61a7 Mon Sep 17 00:00:00 2001
From: XhmikosR <xhmikosr@gmail.com>
Date: Tue, 3 Dec 2019 19:47:21 +0200
Subject: [PATCH 1/2] Use partialCached in some cases.

---
 package.json                             |  2 +-
 site/layouts/_default/404.html           |  4 +-
 site/layouts/_default/docs.html          | 48 ++++++++++++------------
 site/layouts/_default/examples.html      |  2 +-
 site/layouts/_default/home.html          |  4 +-
 site/layouts/_default/single.html        |  6 +--
 site/layouts/partials/docs-navbar.html   | 10 ++---
 site/layouts/partials/docs-subnav.html   |  8 ++--
 site/layouts/partials/header.html        |  4 +-
 site/layouts/partials/home/masthead.html |  2 +-
 10 files changed, 45 insertions(+), 45 deletions(-)

diff --git a/package.json b/package.json
index 24d73df761..fee7659027 100644
--- a/package.json
+++ b/package.json
@@ -48,7 +48,7 @@
     "js-test-jquery": "cross-env JQUERY=true npm run js-test-karma",
     "lint": "npm-run-all --parallel js-lint css-lint lockfile-lint",
     "docs": "npm-run-all docs-build docs-lint",
-    "docs-build": "hugo --cleanDestinationDir",
+    "docs-build": "hugo --cleanDestinationDir --templateMetrics --templateMetricsHints",
     "docs-compile": "npm run docs-build",
     "docs-linkinator": "linkinator _gh_pages --recurse --silent --skip \"^(?!http://localhost)\"",
     "docs-vnu": "node build/vnu-jar.js",
diff --git a/site/layouts/_default/404.html b/site/layouts/_default/404.html
index 744865cd4f..d07c7650d7 100644
--- a/site/layouts/_default/404.html
+++ b/site/layouts/_default/404.html
@@ -4,7 +4,7 @@
     {{ partial "header" . }}
   </head>
   <body class="d-flex flex-column min-vh-100">
-    {{ partial "skippy" . }}
+    {{ partialCached "skippy" . }}
 
     {{ partial "docs-navbar" . }}
 
@@ -12,7 +12,7 @@
       {{ .Content }}
     </main>
 
-    {{ partial "footer" . }}
+    {{ partialCached "footer" . }}
     {{ partial "scripts" . }}
   </body>
 </html>
diff --git a/site/layouts/_default/docs.html b/site/layouts/_default/docs.html
index 5a5b643661..2a255d92dd 100644
--- a/site/layouts/_default/docs.html
+++ b/site/layouts/_default/docs.html
@@ -4,10 +4,10 @@
     {{ partial "header" . }}
   </head>
   <body>
-    {{ partial "skippy" . }}
+    {{ partialCached "skippy" . }}
 
     {{ partial "docs-navbar" . }}
-    {{ partial "docs-subnav" . }}
+    {{ partialCached "docs-subnav" . }}
 
     <div class="container-xxl my-md-4 bd-layout">
       <aside class="bd-sidebar">
@@ -18,39 +18,39 @@
         <div class="bd-intro pl-lg-4">
           <div class="d-md-flex flex-md-row-reverse align-items-center justify-content-between">
             <a class="btn btn-sm btn-bd-light mb-2 mb-md-0" href="{{ .Site.Params.repo }}/blob/main/site/content/{{ .Page.File.Path }}" title="View and edit this file on GitHub" target="_blank" rel="noopener">View on GitHub</a>
-            <h1 class="bd-title" id="content">{{ .Title | markdownify }}</h1>
+        <h1 class="bd-title" id="content">{{ .Title | markdownify }}</h1>
           </div>
-          <p class="bd-lead">{{ .Page.Params.Description | markdownify }}</p>
-          {{ partial "ads" . }}
-        </div>
+        <p class="bd-lead">{{ .Page.Params.Description | markdownify }}</p>
+          {{ partialCached "ads" . }}
+      </div>
 
-        {{ if (eq .Page.Params.toc true) }}
+      {{ if (eq .Page.Params.toc true) }}
           <div class="bd-toc mt-4 mb-5 my-md-0 pl-xl-3 mb-lg-5 text-muted">
-            <strong class="d-block h6 my-2 pb-2 border-bottom">On this page</strong>
-            {{ .TableOfContents }}
-          </div>
-        {{ end }}
+          <strong class="d-block h6 my-2 pb-2 border-bottom">On this page</strong>
+          {{ .TableOfContents }}
+        </div>
+      {{ end }}
 
         <div class="bd-content pl-lg-4">
-          {{ if .Page.Params.sections }}
-            <div class="row g-3">
-              {{ range .Page.Params.sections }}
-              <div class="col-md-6">
-                <a class="d-block text-decoration-none" href="../{{ urlize .title }}/">
-                  <strong class="d-block h5 mb-0">{{ .title }}</strong>
-                  <span class="text-secondary">{{ .description }}</span>
-                </a>
-              </div>
-              {{ end }}
+        {{ if .Page.Params.sections }}
+          <div class="row g-3">
+            {{ range .Page.Params.sections }}
+            <div class="col-md-6">
+              <a class="d-block text-decoration-none" href="../{{ urlize .title }}/">
+                <strong class="d-block h5 mb-0">{{ .title }}</strong>
+                <span class="text-secondary">{{ .description }}</span>
+              </a>
             </div>
-          {{ end }}
+            {{ end }}
+          </div>
+        {{ end }}
 
-          {{ .Content }}
+        {{ .Content }}
         </div>
       </main>
     </div>
 
-    {{ partial "footer" . }}
+    {{ partialCached "footer" . }}
     {{ partial "scripts" . }}
 
     {{ range .Page.Params.extra_js -}}
diff --git a/site/layouts/_default/examples.html b/site/layouts/_default/examples.html
index 3fe1ac9bdd..f4721beec5 100644
--- a/site/layouts/_default/examples.html
+++ b/site/layouts/_default/examples.html
@@ -15,7 +15,7 @@
     {{- end }}
 
     {{ partial "stylesheet" . }}
-    {{ partial "favicons" . }}
+    {{ partialCached "favicons" . }}
 
     <style>
       .bd-placeholder-img {
diff --git a/site/layouts/_default/home.html b/site/layouts/_default/home.html
index 105c86b54b..680a0700d6 100644
--- a/site/layouts/_default/home.html
+++ b/site/layouts/_default/home.html
@@ -4,7 +4,7 @@
     {{ partial "header" . }}
   </head>
   <body>
-    {{ partial "skippy" . }}
+    {{ partialCached "skippy" . }}
 
     {{ partial "docs-navbar" . }}
 
@@ -15,7 +15,7 @@
 
     {{ .Content }}
 
-    {{ partial "footer" . }}
+    {{ partialCached "footer" . }}
     {{ partial "scripts" . }}
   </body>
 </html>
diff --git a/site/layouts/_default/single.html b/site/layouts/_default/single.html
index fd228314f4..32d86004aa 100644
--- a/site/layouts/_default/single.html
+++ b/site/layouts/_default/single.html
@@ -4,7 +4,7 @@
     {{ partial "header" . }}
   </head>
   <body>
-    {{ partial "skippy" . }}
+    {{ partialCached "skippy" . }}
 
     {{ partial "docs-navbar" . }}
 
@@ -18,7 +18,7 @@
           <a href="{{ .Site.Params.download.source }}" class="btn btn-lg btn-outline-secondary mt-3 mt-sm-0 ml-sm-3" onclick="ga('send', 'event', 'Examples', 'Hero', 'Download');">Download source code</a>
         </div>
         {{ end }}
-        {{ partial "ads" . }}
+        {{ partialCached "ads" . }}
       </div>
     </header>
 
@@ -48,7 +48,7 @@
       </div>
     </main>
 
-    {{ partial "footer" . }}
+    {{ partialCached "footer" . }}
     {{ partial "scripts" . }}
   </body>
 </html>
diff --git a/site/layouts/partials/docs-navbar.html b/site/layouts/partials/docs-navbar.html
index 46e43b81e1..aeb7eafc16 100644
--- a/site/layouts/partials/docs-navbar.html
+++ b/site/layouts/partials/docs-navbar.html
@@ -1,7 +1,7 @@
 <header class="navbar navbar-expand-md navbar-dark bd-navbar">
   <nav class="container-xxl flex-wrap flex-md-nowrap" aria-label="Main navigation">
     <a class="navbar-brand p-0 mr-2" href="/" aria-label="Bootstrap">
-      {{ partial "icons/bootstrap-white-fill.svg" (dict "class" "d-block my-1" "width" "40" "height" "32") }}
+      {{ partialCached "icons/bootstrap-white-fill.svg" (dict "class" "d-block my-1" "width" "40" "height" "32") }}
     </a>
 
     <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#bdNavbar" aria-controls="bdNavbar" aria-expanded="false" aria-label="Toggle navigation">
@@ -37,25 +37,25 @@
       <ul class="navbar-nav flex-row flex-wrap ml-md-auto">
         <li class="nav-item col-6 col-md-auto">
           <a class="nav-link p-2" href="{{ .Site.Params.github_org }}" target="_blank" rel="noopener">
-            {{ partial "icons/github.svg" (dict "class" "navbar-nav-svg d-inline-block align-text-top" "width" "36" "height" "36") }}
+            {{ partialCached "icons/github.svg" (dict "class" "navbar-nav-svg d-inline-block align-text-top" "width" "36" "height" "36") }}
             <small class="d-md-none ml-2">GitHub</small>
           </a>
         </li>
         <li class="nav-item col-6 col-md-auto">
           <a class="nav-link p-2" href="https://twitter.com/{{ .Site.Params.twitter }}" target="_blank" rel="noopener">
-            {{ partial "icons/twitter.svg" (dict "class" "navbar-nav-svg d-inline-block align-text-top" "width" "36" "height" "36") }}
+            {{ partialCached "icons/twitter.svg" (dict "class" "navbar-nav-svg d-inline-block align-text-top" "width" "36" "height" "36") }}
             <small class="d-md-none ml-2">Twitter</small>
           </a>
         </li>
         <li class="nav-item col-6 col-md-auto">
           <a class="nav-link p-2" href="{{ .Site.Params.slack }}" target="_blank" rel="noopener">
-            {{ partial "icons/slack.svg" (dict "class" "navbar-nav-svg d-inline-block align-text-top" "width" "36" "height" "36") }}
+            {{ partialCached "icons/slack.svg" (dict "class" "navbar-nav-svg d-inline-block align-text-top" "width" "36" "height" "36") }}
             <small class="d-md-none ml-2">Slack</small>
           </a>
         </li>
         <li class="nav-item col-6 col-md-auto">
           <a class="nav-link p-2" href="{{ .Site.Params.opencollective }}" target="_blank" rel="noopener">
-            {{ partial "icons/opencollective.svg" (dict "class" "navbar-nav-svg d-inline-block align-text-top" "width" "36" "height" "36") }}
+            {{ partialCached "icons/opencollective.svg" (dict "class" "navbar-nav-svg d-inline-block align-text-top" "width" "36" "height" "36") }}
             <small class="d-md-none ml-2">Open Collective</small>
           </a>
         </li>
diff --git a/site/layouts/partials/docs-subnav.html b/site/layouts/partials/docs-subnav.html
index e036d83652..86ace1bac3 100644
--- a/site/layouts/partials/docs-subnav.html
+++ b/site/layouts/partials/docs-subnav.html
@@ -4,11 +4,11 @@
       <input type="search" class="form-control" id="search-input" placeholder="Search docs..." aria-label="Search docs for..." autocomplete="off" data-docs-version="{{ .Site.Params.docs_version }}">
     </form>
 
-    {{ partial "docs-versions" . }}
+    {{ partialCached "docs-versions" . }}
 
     <button class="btn bd-sidebar-toggle d-md-none py-0 px-1 ml-3 order-3 collapsed" type="button" data-toggle="collapse" data-target="#bd-docs-nav" aria-controls="bd-docs-nav" aria-expanded="false" aria-label="Toggle docs navigation">
-      {{ partial "icons/expand.svg" (dict "class" "bi bi-expand" "width" "24" "height" "24") }}
-      {{ partial "icons/collapse.svg" (dict "class" "bi bi-collapse" "width" "24" "height" "24") }}
-    </button>
+      {{ partialCached "icons/expand.svg" (dict "class" "bi bi-expand" "width" "24" "height" "24") }}
+      {{ partialCached "icons/collapse.svg" (dict "class" "bi bi-collapse" "width" "24" "height" "24") }}
+   </button>
   </div>
 </nav>
diff --git a/site/layouts/partials/header.html b/site/layouts/partials/header.html
index 2d2eb29d9f..af67bfc289 100644
--- a/site/layouts/partials/header.html
+++ b/site/layouts/partials/header.html
@@ -16,6 +16,6 @@
 {{- end }}
 
 {{ partial "stylesheet" . }}
-{{ partial "favicons" . }}
+{{ partialCached "favicons" . }}
 {{ partial "social" . }}
-{{ partial "analytics" . }}
+{{ partialCached "analytics" . }}
diff --git a/site/layouts/partials/home/masthead.html b/site/layouts/partials/home/masthead.html
index 4ca26104dc..0cae31d95f 100644
--- a/site/layouts/partials/home/masthead.html
+++ b/site/layouts/partials/home/masthead.html
@@ -21,6 +21,6 @@
         </p>
       </div>
     </div>
-    {{ partial "ads.html" . }}
+    {{ partialCached "ads.html" . }}
   </div>
 </div>
-- 
GitLab


From a250b0b094d31845ffcdedbdfb84b69b09b6c8cd Mon Sep 17 00:00:00 2001
From: Regis Philibert <login@regisphilibert.com>
Date: Tue, 14 Jan 2020 09:02:21 -0500
Subject: [PATCH 2/2] Improve partial caching logic (#29952)

More partials are cached by dding "variations" arguments when possible.

See comments in file.
---
 site/layouts/_default/404.html      |  2 +-
 site/layouts/_default/docs.html     |  2 +-
 site/layouts/_default/examples.html |  4 ++--
 site/layouts/_default/home.html     |  2 +-
 site/layouts/_default/single.html   |  3 ++-
 site/layouts/partials/header.html   | 11 ++++++++---
 6 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/site/layouts/_default/404.html b/site/layouts/_default/404.html
index d07c7650d7..e106c3d91a 100644
--- a/site/layouts/_default/404.html
+++ b/site/layouts/_default/404.html
@@ -6,7 +6,7 @@
   <body class="d-flex flex-column min-vh-100">
     {{ partialCached "skippy" . }}
 
-    {{ partial "docs-navbar" . }}
+    {{ partialCached "docs-navbar" . "404" }}
 
     <main class="my-auto p-5" id="content">
       {{ .Content }}
diff --git a/site/layouts/_default/docs.html b/site/layouts/_default/docs.html
index 2a255d92dd..a4f9cd298f 100644
--- a/site/layouts/_default/docs.html
+++ b/site/layouts/_default/docs.html
@@ -6,7 +6,7 @@
   <body>
     {{ partialCached "skippy" . }}
 
-    {{ partial "docs-navbar" . }}
+    {{ partialCached "docs-navbar" . "docs" }}
     {{ partialCached "docs-subnav" . }}
 
     <div class="container-xxl my-md-4 bd-layout">
diff --git a/site/layouts/_default/examples.html b/site/layouts/_default/examples.html
index f4721beec5..1bcf1a9310 100644
--- a/site/layouts/_default/examples.html
+++ b/site/layouts/_default/examples.html
@@ -13,8 +13,8 @@
     {{ with .Params.robots -}}
     <meta name="robots" content="{{ . }}">
     {{- end }}
-
-    {{ partial "stylesheet" . }}
+    {{/* Only this layout sports its own variation of the "stylesheet" partial */}}
+    {{ partialCached "stylesheet" . "examples" }}
     {{ partialCached "favicons" . }}
 
     <style>
diff --git a/site/layouts/_default/home.html b/site/layouts/_default/home.html
index 680a0700d6..0bac8dfbc6 100644
--- a/site/layouts/_default/home.html
+++ b/site/layouts/_default/home.html
@@ -6,7 +6,7 @@
   <body>
     {{ partialCached "skippy" . }}
 
-    {{ partial "docs-navbar" . }}
+    {{ partialCached "docs-navbar" . "home" }}
 
     <main>
       {{ partial "home/masthead" . }}
diff --git a/site/layouts/_default/single.html b/site/layouts/_default/single.html
index 32d86004aa..c27ad367aa 100644
--- a/site/layouts/_default/single.html
+++ b/site/layouts/_default/single.html
@@ -6,7 +6,8 @@
   <body>
     {{ partialCached "skippy" . }}
 
-    {{ partial "docs-navbar" . }}
+
+    {{ partialCached "docs-navbar" . "single" }}
 
     <header class="py-5 border-bottom">
       <div class="container pt-md-1 pb-md-4">
diff --git a/site/layouts/partials/header.html b/site/layouts/partials/header.html
index af67bfc289..17967f3469 100644
--- a/site/layouts/partials/header.html
+++ b/site/layouts/partials/header.html
@@ -14,8 +14,13 @@
 {{ with .Params.robots -}}
 <meta name="robots" content="{{ . }}">
 {{- end }}
-
-{{ partial "stylesheet" . }}
+{{/* stylesheet partial only has two variations: 
+  one for pages with the "example" layout and one other pages.
+  On "default" pages uses the current template file, so we can safely use
+  the "default" variant. */}}
+{{ partialCached "stylesheet" . "default" }}
 {{ partialCached "favicons" . }}
-{{ partial "social" . }}
+{{/* There is only two variations for the social partial.
+  One for the homepage and one for the rest */}}
+{{ partialCached "social" . (cond .IsHome "home" "default") }}
 {{ partialCached "analytics" . }}
-- 
GitLab