Skip to content

Commit 835579b

Browse files
committed
Re-introduce the LRU-evicted identities in change set calculation
This is a follow up to db28695 -- that commit dropped the cache items evicted in the LRU process. This was done as performance optimization for large Hugo sites. That made much sense, but now there's a slight chance that we miss out on a change when rebuilding. This commit fixes this by applying the same logic to the evicted items as if they were still in the cache. This should preserve the performance gains in db28695 and close the hole for the possible false negatives.
1 parent 05e067c commit 835579b

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

hugolib/content_map_page.go

+22-1
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ func (h *HugoSites) resolveAndClearStateForIdentities(
11241124
cachebuster func(s string) bool, changes []identity.Identity,
11251125
) error {
11261126
// Drain the cache eviction stack to start fresh.
1127-
h.Deps.MemCache.DrainEvictedIdentities()
1127+
evictedStart := h.Deps.MemCache.DrainEvictedIdentities()
11281128

11291129
h.Log.Debug().Log(logg.StringFunc(
11301130
func() string {
@@ -1200,6 +1200,27 @@ func (h *HugoSites) resolveAndClearStateForIdentities(
12001200
for _, c := range evicted {
12011201
changes = append(changes, c.Identity)
12021202
}
1203+
1204+
if len(evictedStart) > 0 {
1205+
// In low memory situations and/or very big sites, there can be a lot of unrelated evicted items,
1206+
// but there's a chance that some of them are related to the changes we are about to process,
1207+
// so check.
1208+
depsFinder := identity.NewFinder(identity.FinderConfig{})
1209+
var addends []identity.Identity
1210+
for _, ev := range evictedStart {
1211+
for _, id := range changes {
1212+
if cachebuster != nil && cachebuster(ev.Key.(string)) {
1213+
addends = append(addends, ev.Identity)
1214+
break
1215+
}
1216+
if r := depsFinder.Contains(id, ev.Identity, -1); r > 0 {
1217+
addends = append(addends, ev.Identity)
1218+
break
1219+
}
1220+
}
1221+
}
1222+
changes = append(changes, addends...)
1223+
}
12031224
} else {
12041225
// Mass eviction, we might as well invalidate everything.
12051226
changes = []identity.Identity{identity.GenghisKhan}

0 commit comments

Comments
 (0)