Skip to content

Commit

Permalink
perf: simplify the hashing method
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed May 14, 2023
1 parent 9611d9d commit e6d2d90
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions layouts/partials/search/assets/js-resource.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
{{- range .Sites }}
{{- $site := . }}
{{- with .Home.OutputFormats.Get "SearchIndex" }}
{{- $idxCtx := dict "Site" $site "Index" . }}
{{- $indexURL := partialCached "search/functions/search-index-url" $idxCtx $idxCtx }}
{{- $hash := partialCached "search/functions/search-index-hash" $site $site }}
{{- $indexURL := printf "%s?v=%s" .RelPermalink $hash }}
{{- $indices = $indices | append $indexURL }}
{{- end }}
{{- end }}
Expand Down
4 changes: 4 additions & 0 deletions layouts/partials/search/functions/pages.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{- $indexAllPages := default true .Site.Params.search.index_all_pages -}}
{{- $pages := cond $indexAllPages .Site.Pages .Site.RegularPages -}}
{{- $pages = where $pages "Params.noindex" "ne" true -}}
{{- return $pages }}
9 changes: 9 additions & 0 deletions layouts/partials/search/functions/search-index-hash.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{/* This hashing function just calculate the number of pages and the lastmod time. */}}
{{- $ctx := dict "Site" . }}
{{- $pages := partialCached "search/functions/pages" $ctx $ctx -}}
{{- $hash := printf "total=%d" $pages.Len }}
{{- $latest := first 1 $pages.ByLastmod.Reverse }}
{{- with index $latest 0 }}
{{- $hash = printf "%s&lastmod=%d" $hash .Lastmod.Unix }}
{{- end }}
{{- return ($hash | md5) }}
3 changes: 0 additions & 3 deletions layouts/partials/search/functions/search-index-url.html

This file was deleted.

5 changes: 2 additions & 3 deletions layouts/partials/search/index.json.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{{- $items := slice -}}
{{- $indexContent := default false .Site.Params.search.index_content -}}
{{- $years := true }}
{{- $indexAllPages := default true .Site.Params.search.index_all_pages -}}
{{- $pages := cond $indexAllPages .Site.Pages .Site.RegularPages -}}
{{- $pages = where $pages "Params.noindex" "ne" true -}}
{{- $pagesCtx := dict "Site" .Site }}
{{- $pages := partialCached "search/functions/pages" $pagesCtx $pagesCtx -}}
{{- range $pages -}}
{{- $page := . -}}
{{- $item := newScratch -}}
Expand Down

0 comments on commit e6d2d90

Please sign in to comment.