feat: image variants cache panel
This commit is contained in:
1 parent
951fef18ba
commit
d768668014
53 files changed
+5809
-46
No files matched your search
@@ -84,6 +84,8 @@ const (
|
||||
ActionVariantPurge = "media.variant_purge"
|
||||
ActionVariantGenerateAll = "media.variant_generate_all"
|
||||
ActionVariantPurgeImage = "media.variant_purge_image"
|
||||
ActionVariantPurgeAll = "media.variant_purge_all"
|
||||
ActionVariantPurgeUnused = "media.variant_purge_unused"
|
||||
ActionUserRegister = "user.register"
|
||||
ActionUserVerify = "user.verify"
|
||||
ActionUserUpdateProfile = "user.update_profile"
|
||||
@@ -123,6 +125,8 @@ const (
|
||||
ParamKind = "kind"
|
||||
ParamPurgedFiles = "purged_files"
|
||||
ParamPurgedBytes = "purged_bytes"
|
||||
ParamFailedFiles = "failed_files"
|
||||
ParamOlderThanDays = "older_than_days"
|
||||
ParamGenerated = "generated"
|
||||
ParamFailed = "failed"
|
||||
ParamCauses = "causes"
|
||||
|
||||
@@ -15,6 +15,7 @@ type Repository interface {
|
||||
ListDuplicates() ([]Image, error)
|
||||
Counts() (Counts, error)
|
||||
ExistsByStoredName(storedName string) (bool, error)
|
||||
ListByStoredNames(storedNames []string) ([]Image, error)
|
||||
ListMissingMetadata() ([]Image, error)
|
||||
UpdateMetadata(id uint32, metadata Metadata) error
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
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
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
package image
|
||||
|
||||
import "io"
|
||||
import (
|
||||
"io"
|
||||
"time"
|
||||
)
|
||||
|
||||
type VariantRepository interface {
|
||||
List() ([]Variant, error)
|
||||
@@ -20,6 +23,23 @@ type VariantFileRepository interface {
|
||||
TotalsBySource() (map[string]VariantFileTotals, error)
|
||||
}
|
||||
|
||||
type VariantCacheRepository interface {
|
||||
UnusedTotals(filter UnusedFilter) (VariantFileTotals, error)
|
||||
TopSources(limit int) ([]SourceTotals, error)
|
||||
ListPage(filter VariantFileFilter, afterID uint32, limit int) ([]VariantFile, error)
|
||||
}
|
||||
|
||||
type VariantUsageRepository interface {
|
||||
Record(batch VariantUsageBatch) error
|
||||
RejectedSince(day time.Time) (int, error)
|
||||
}
|
||||
|
||||
type VariantUsageTracker interface {
|
||||
RecordHit(variantName string, sourceName string)
|
||||
RecordRejection()
|
||||
Flush() error
|
||||
}
|
||||
|
||||
type RenderedVariant struct {
|
||||
Content []byte
|
||||
ContentType string
|
||||
|
||||
Reference in new issue
Block a user