summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2024-02-02 11:20:08 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2024-02-04 16:55:06 +0100
commit609d798e342c873143cf7ad05e987f3d8f7fbb45 (patch)
treea47532d5ba4acf3f12aad25791ee24ff802af35e /hugolib
parent53f204310ec8362d7084c123e8e16f5bb73dd257 (diff)
Handle resource changes when the resources is already evicted from cache
Also fix a logical flaw in the cache resizer that made it too aggressive. After this I haven't been able to reproduce #11988, but I need to look closer. Closes #11973 Updates #11988
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/content_map_page.go17
-rw-r--r--hugolib/hugo_sites.go7
-rw-r--r--hugolib/hugo_sites_build.go6
3 files changed, 18 insertions, 12 deletions
diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go
index 1f4cd0880..570e45bd4 100644
--- a/hugolib/content_map_page.go
+++ b/hugolib/content_map_page.go
@@ -1018,14 +1018,6 @@ func (h *HugoSites) resolveAndClearStateForIdentities(
b = cachebuster(s)
}
- if b {
- identity.WalkIdentitiesShallow(v, func(level int, id identity.Identity) bool {
- // Add them to the change set so we can reset any page that depends on them.
- changes = append(changes, id)
- return false
- })
- }
-
return b
}
@@ -1037,6 +1029,15 @@ func (h *HugoSites) resolveAndClearStateForIdentities(
}
}
+ // Drain the the cache eviction stack.
+ evicted := h.Deps.MemCache.DrainEvictedIdentities()
+ if len(evicted) < 200 {
+ changes = append(changes, evicted...)
+ } else {
+ // Mass eviction, we might as well invalidate everything.
+ changes = []identity.Identity{identity.GenghisKhan}
+ }
+
// Remove duplicates
seen := make(map[identity.Identity]bool)
var n int
diff --git a/hugolib/hugo_sites.go b/hugolib/hugo_sites.go
index ef67b1059..24ff1077f 100644
--- a/hugolib/hugo_sites.go
+++ b/hugolib/hugo_sites.go
@@ -99,6 +99,8 @@ type HugoSites struct {
*fatalErrorHandler
*buildCounters
+ // Tracks invocations of the Build method.
+ buildCounter atomic.Uint64
}
// ShouldSkipFileChangeEvent allows skipping filesystem event early before
@@ -420,10 +422,9 @@ func (cfg *BuildCfg) shouldRender(p *pageState) bool {
return false
}
- fastRenderMode := cfg.RecentlyVisited.Len() > 0
+ fastRenderMode := p.s.Conf.FastRenderMode()
- if !fastRenderMode {
- // Not in fast render mode or first time render.
+ if !fastRenderMode || p.s.h.buildCounter.Load() == 0 {
return shouldRender
}
diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go
index a15e15504..4b22c1956 100644
--- a/hugolib/hugo_sites_build.go
+++ b/hugolib/hugo_sites_build.go
@@ -57,6 +57,9 @@ import (
func (h *HugoSites) Build(config BuildCfg, events ...fsnotify.Event) error {
infol := h.Log.InfoCommand("build")
defer loggers.TimeTrackf(infol, time.Now(), nil, "")
+ defer func() {
+ h.buildCounter.Add(1)
+ }()
if h.Deps == nil {
panic("must have deps")
@@ -769,8 +772,9 @@ func (h *HugoSites) processPartial(ctx context.Context, l logg.LevelLogger, conf
}
case files.ComponentFolderAssets:
logger.Println("Asset changed", pathInfo.Path())
- r, _ := h.ResourceSpec.ResourceCache.Get(context.Background(), dynacache.CleanKey(pathInfo.Base()))
+
var hasID bool
+ r, _ := h.ResourceSpec.ResourceCache.Get(context.Background(), dynacache.CleanKey(pathInfo.Base()))
identity.WalkIdentitiesShallow(r, func(level int, rid identity.Identity) bool {
hasID = true
changes = append(changes, rid)