77 lines
1.5 KiB
Go
77 lines
1.5 KiB
Go
package image
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
)
|
|
|
|
var ErrCachePurgeScope = errors.New("cache purge scope is not valid")
|
|
|
|
type CachePurgeScope string
|
|
|
|
const (
|
|
CacheScopeAll CachePurgeScope = "all"
|
|
CacheScopeUnused CachePurgeScope = "unused"
|
|
CacheScopeVariant CachePurgeScope = "variant"
|
|
CacheScopeImage CachePurgeScope = "image"
|
|
)
|
|
|
|
const (
|
|
UnusedVariantDays = 30
|
|
RejectionWindowDays = 7
|
|
TopImagesLimit = 10
|
|
CachePurgeBatchSize = 500
|
|
RejectionDayLayout = "2006-01-02"
|
|
)
|
|
|
|
func UnusedCutoff(now time.Time) time.Time {
|
|
return now.UTC().AddDate(0, 0, -UnusedVariantDays)
|
|
}
|
|
|
|
func RejectionDay(at time.Time) time.Time {
|
|
utc := at.UTC()
|
|
return time.Date(utc.Year(), utc.Month(), utc.Day(), 0, 0, 0, 0, time.UTC)
|
|
}
|
|
|
|
func RejectionWindowStart(now time.Time) time.Time {
|
|
return RejectionDay(now).AddDate(0, 0, -(RejectionWindowDays - 1))
|
|
}
|
|
|
|
func RejectionPruneBefore(now time.Time) time.Time {
|
|
return RejectionDay(now).AddDate(0, 0, -RejectionWindowDays)
|
|
}
|
|
|
|
type UnusedFilter struct {
|
|
VariantNames []string
|
|
Cutoff time.Time
|
|
}
|
|
|
|
type VariantFileFilter struct {
|
|
VariantName string
|
|
SourceName string
|
|
Unused *UnusedFilter
|
|
}
|
|
|
|
type SourceTotals struct {
|
|
SourceName string
|
|
Files int
|
|
Bytes int64
|
|
}
|
|
|
|
type VariantHit struct {
|
|
VariantName string
|
|
SourceName string
|
|
At time.Time
|
|
}
|
|
|
|
type RejectionCount struct {
|
|
Day time.Time
|
|
Count int
|
|
}
|
|
|
|
type VariantUsageBatch struct {
|
|
Hits []VariantHit
|
|
Rejections []RejectionCount
|
|
PruneBefore time.Time
|
|
}
|