refac: atomic merge, lost-update race, RunPurge cost, duplicated walks

This commit is contained in:
Florian Sylvain committed 2026-10-21 22:47:46 +02:00
1 parent 0fc3511e2b
commit 074944c99a
45 files changed
+2204 -267

No files matched your search

+11 -2
View File
@@ -23,6 +23,7 @@ type purgePlan struct {
copies int
articles int
fingerprint string
entries *entryMediaIndex
}
type purgePlanner struct {
@@ -43,7 +44,15 @@ func (p *purgePlanner) plan() (purgePlan, error) {
return purgePlan{}, err
}
siteUsage, err := imageUsageCount(p.sites, p.authors, p.entries)
var entryIndex *entryMediaIndex
siteUsage, err := combinedImageUsage(p.sites, p.authors, func() (map[uint32]int, error) {
built, err := p.entries.index()
if err != nil {
return nil, err
}
entryIndex = built
return built.usageCounts(), nil
})
if err != nil {
return purgePlan{}, err
}
@@ -64,7 +73,7 @@ func (p *purgePlanner) plan() (purgePlan, error) {
}
slices.SortFunc(groups, func(a, b purgeGroup) int { return int(a.kept.ID) - int(b.kept.ID) })
return purgePlan{groups: groups, copies: copies, articles: len(touched), fingerprint: fingerprintOf(groups)}, nil
return purgePlan{groups: groups, copies: copies, articles: len(touched), fingerprint: fingerprintOf(groups), entries: entryIndex}, nil
}
func groupByHash(images []image.Image) [][]image.Image {