refac: removed 7 direct and 12 indirect go modules for custom code instead

This commit is contained in:
Florian Sylvain committed 2026-10-21 23:13:46 +02:00
1 parent cfcf108488
commit c68e9a7858
73 files changed
+2455 -428

No files matched your search

@@ -11,8 +11,6 @@ import (
"slices"
"strings"
"time"
"golang.org/x/sync/singleflight"
)
const (
@@ -54,7 +52,7 @@ type ServeVariantUseCase struct {
maxSourceBytes int64
maxSourcePixels int64
renderSlots chan struct{}
flights singleflight.Group
flights flightGroup
tracker image.VariantUsageTracker
}
@@ -214,11 +212,11 @@ func (u *ServeVariantUseCase) lookupCached(variantName string, storedName string
func (u *ServeVariantUseCase) generated(ctx context.Context, variant image.Variant, storedName string, fingerprint string, previous image.VariantFile) (image.VariantFile, error) {
key := strings.Join([]string{variant.Name, fingerprint, storedName}, flightKeySep)
for {
file, err, _ := u.flights.Do(key, func() (any, error) {
file, err := u.flights.do(key, func() (image.VariantFile, error) {
return u.generate(ctx, variant, storedName, fingerprint, previous)
})
if err == nil {
return file.(image.VariantFile), nil
return file, nil
}
if ctx.Err() != nil || !errors.Is(err, context.Canceled) {
return image.VariantFile{}, err
@@ -0,0 +1,45 @@
package useCases
import (
"RenewCMS/internal/domain/image"
"errors"
"sync"
)
var errFlightAbandoned = errors.New("shared call ended without a result")
type flightCall struct {
done chan struct{}
value image.VariantFile
err error
}
type flightGroup struct {
mu sync.Mutex
calls map[string]*flightCall
}
func (g *flightGroup) do(key string, work func() (image.VariantFile, error)) (image.VariantFile, error) {
g.mu.Lock()
if existing, running := g.calls[key]; running {
g.mu.Unlock()
<-existing.done
return existing.value, existing.err
}
if g.calls == nil {
g.calls = map[string]*flightCall{}
}
call := &flightCall{done: make(chan struct{}), err: errFlightAbandoned}
g.calls[key] = call
g.mu.Unlock()
defer func() {
g.mu.Lock()
delete(g.calls, key)
g.mu.Unlock()
close(call.done)
}()
call.value, call.err = work()
return call.value, call.err
}