Add scan option to force gallery zip rescan (#4113)

* Add scan option to force rescan
---------
Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
CJ 2024-05-19 22:52:36 -05:00 committed by GitHub
parent 5ba1ea8fbc
commit 0fa71be697
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 24 additions and 6 deletions

View file

@ -75,6 +75,8 @@ input ScanMetaDataFilterInput {
input ScanMetadataInput { input ScanMetadataInput {
paths: [String!] paths: [String!]
"Forces a rescan on files even if modification time is unchanged"
rescan: Boolean
"Generate covers during scan" "Generate covers during scan"
scanGenerateCovers: Boolean scanGenerateCovers: Boolean
"Generate previews during scan" "Generate previews during scan"
@ -95,6 +97,8 @@ input ScanMetadataInput {
} }
type ScanMetadataOptions { type ScanMetadataOptions {
"Forces a rescan on files even if modification time is unchanged"
rescan: Boolean!
"Generate covers during scan" "Generate covers during scan"
scanGenerateCovers: Boolean! scanGenerateCovers: Boolean!
"Generate previews during scan" "Generate previews during scan"

View file

@ -1,6 +1,8 @@
package config package config
type ScanMetadataOptions struct { type ScanMetadataOptions struct {
// Forces a rescan on files even if they have not changed
Rescan bool `json:"rescan"`
// Generate scene covers during scan // Generate scene covers during scan
ScanGenerateCovers bool `json:"scanGenerateCovers"` ScanGenerateCovers bool `json:"scanGenerateCovers"`
// Generate previews during scan // Generate previews during scan

View file

@ -35,6 +35,7 @@ type ScanJob struct {
} }
func (j *ScanJob) Execute(ctx context.Context, progress *job.Progress) error { func (j *ScanJob) Execute(ctx context.Context, progress *job.Progress) error {
cfg := config.GetInstance()
input := j.input input := j.input
if job.IsCancelled(ctx) { if job.IsCancelled(ctx) {
@ -55,7 +56,7 @@ func (j *ScanJob) Execute(ctx context.Context, progress *job.Progress) error {
start := time.Now() start := time.Now()
const taskQueueSize = 200000 const taskQueueSize = 200000
taskQueue := job.NewTaskQueue(ctx, progress, taskQueueSize, c.GetParallelTasksWithAutoDetection()) taskQueue := job.NewTaskQueue(ctx, progress, taskQueueSize, cfg.GetParallelTasksWithAutoDetection())
var minModTime time.Time var minModTime time.Time
if j.input.Filter != nil && j.input.Filter.MinModTime != nil { if j.input.Filter != nil && j.input.Filter.MinModTime != nil {
@ -65,9 +66,10 @@ func (j *ScanJob) Execute(ctx context.Context, progress *job.Progress) error {
j.scanner.Scan(ctx, getScanHandlers(j.input, taskQueue, progress), file.ScanOptions{ j.scanner.Scan(ctx, getScanHandlers(j.input, taskQueue, progress), file.ScanOptions{
Paths: paths, Paths: paths,
ScanFilters: []file.PathFilter{newScanFilter(c, repo, minModTime)}, ScanFilters: []file.PathFilter{newScanFilter(c, repo, minModTime)},
ZipFileExtensions: c.GetGalleryExtensions(), ZipFileExtensions: cfg.GetGalleryExtensions(),
ParallelTasks: c.GetParallelTasksWithAutoDetection(), ParallelTasks: cfg.GetParallelTasksWithAutoDetection(),
HandlerRequiredFilters: []file.Filter{newHandlerRequiredFilter(c, repo)}, HandlerRequiredFilters: []file.Filter{newHandlerRequiredFilter(cfg, repo)},
Rescan: j.input.Rescan,
}, progress) }, progress)
taskQueue.Close() taskQueue.Close()

View file

@ -134,6 +134,9 @@ type ScanOptions struct {
HandlerRequiredFilters []Filter HandlerRequiredFilters []Filter
ParallelTasks int ParallelTasks int
// When true files in path will be rescanned even if they haven't changed
Rescan bool
} }
// Scan starts the scanning process. // Scan starts the scanning process.
@ -1023,14 +1026,20 @@ func (s *scanJob) onExistingFile(ctx context.Context, f scanFile, existing model
fileModTime := f.ModTime fileModTime := f.ModTime
updated := !fileModTime.Equal(base.ModTime) updated := !fileModTime.Equal(base.ModTime)
forceRescan := s.options.Rescan
if !updated { if !updated && !forceRescan {
return s.onUnchangedFile(ctx, f, existing) return s.onUnchangedFile(ctx, f, existing)
} }
oldBase := *base oldBase := *base
logger.Infof("%s has been updated: rescanning", path) if !updated && forceRescan {
logger.Infof("rescanning %s", path)
} else {
logger.Infof("%s has been updated: rescanning", path)
}
base.ModTime = fileModTime base.ModTime = fileModTime
base.Size = f.Size base.Size = f.Size
base.UpdatedAt = time.Now() base.UpdatedAt = time.Now()

View file

@ -151,6 +151,7 @@ fragment ScraperSourceData on ScraperSource {
fragment ConfigDefaultSettingsData on ConfigDefaultSettingsResult { fragment ConfigDefaultSettingsData on ConfigDefaultSettingsResult {
scan { scan {
# don't get rescan - it should never be defaulted to true
scanGenerateCovers scanGenerateCovers
scanGeneratePreviews scanGeneratePreviews
scanGenerateImagePreviews scanGenerateImagePreviews