diff options
author | Bjørn Erik Pedersen <[email protected]> | 2024-04-20 11:05:35 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2024-04-20 15:09:12 +0200 |
commit | 004b6943906471cff0d0232040d24cff6cb89e6b (patch) | |
tree | 75d2492a0553a283c16a26cb5df9a178c5baa5ec /hugolib | |
parent | da6112fc65346d0f4e12b52d0580258cf02716c9 (diff) | |
download | hugo-004b6943906471cff0d0232040d24cff6cb89e6b.tar.gz hugo-004b6943906471cff0d0232040d24cff6cb89e6b.zip |
Fix partial rebuilds for SCSS fetched with GetMatch and similar
Fixes #12395
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/content_map_page.go | 2 | ||||
-rw-r--r-- | hugolib/hugo_sites_build.go | 46 |
2 files changed, 40 insertions, 8 deletions
diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go index aa32b5320..50e1bc35d 100644 --- a/hugolib/content_map_page.go +++ b/hugolib/content_map_page.go @@ -1084,7 +1084,7 @@ func (h *HugoSites) resolveAndClearStateForIdentities( return b } - h.MemCache.ClearMatching(shouldDelete) + h.MemCache.ClearMatching(nil, shouldDelete) return ll, nil }); err != nil { diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go index 411f90734..3beb072e3 100644 --- a/hugolib/hugo_sites_build.go +++ b/hugolib/hugo_sites_build.go @@ -23,6 +23,7 @@ import ( "path" "path/filepath" "strings" + "sync" "time" "github.com/bep/logg" @@ -46,6 +47,7 @@ import ( "github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/page/siteidentities" "github.com/gohugoio/hugo/resources/postpub" + "github.com/gohugoio/hugo/resources/resource" "github.com/spf13/afero" @@ -758,15 +760,45 @@ func (h *HugoSites) processPartial(ctx context.Context, l logg.LevelLogger, conf } } case files.ComponentFolderAssets: - logger.Println("Asset changed", pathInfo.Path()) + p := pathInfo.Path() + logger.Println("Asset changed", p) + + var matches []any + var mu sync.Mutex + + h.MemCache.ClearMatching( + func(k string, pm dynacache.PartitionManager) bool { + // Avoid going through everything. + return strings.HasPrefix(k, "/res") + }, + func(k, v any) bool { + if strings.Contains(k.(string), p) { + mu.Lock() + defer mu.Unlock() + switch vv := v.(type) { + case resource.Resources: + // GetMatch/Match. + for _, r := range vv { + matches = append(matches, r) + } + return true + default: + matches = append(matches, vv) + return true + + } + } + return false + }) 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) - return false - }) + for _, r := range matches { + identity.WalkIdentitiesShallow(r, func(level int, rid identity.Identity) bool { + hasID = true + changes = append(changes, rid) + return false + }) + } if !hasID { changes = append(changes, pathInfo) } |