Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scan option to force gallery zip rescan #4113

4 changes: 4 additions & 0 deletions graphql/schema/types/metadata.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ input ScanMetaDataFilterInput {
input ScanMetadataInput {
paths: [String!]

"Forces a rescan on files even if modification time is unchanged"
rescan: Boolean
"Generate covers during scan"
scanGenerateCovers: Boolean
"Generate previews during scan"
Expand All @@ -95,6 +97,8 @@ input ScanMetadataInput {
}

type ScanMetadataOptions {
"Forces a rescan on files even if modification time is unchanged"
rescan: Boolean!
"Generate covers during scan"
scanGenerateCovers: Boolean!
"Generate previews during scan"
Expand Down
2 changes: 2 additions & 0 deletions internal/manager/config/tasks.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package config

type ScanMetadataOptions struct {
// Forces a rescan on files even if they have not changed
Rescan bool `json:"rescan"`
// Generate scene covers during scan
ScanGenerateCovers bool `json:"scanGenerateCovers"`
// Generate previews during scan
Expand Down
10 changes: 6 additions & 4 deletions internal/manager/task_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type ScanJob struct {
}

func (j *ScanJob) Execute(ctx context.Context, progress *job.Progress) error {
cfg := config.GetInstance()
input := j.input

if job.IsCancelled(ctx) {
Expand All @@ -55,7 +56,7 @@ func (j *ScanJob) Execute(ctx context.Context, progress *job.Progress) error {
start := time.Now()

const taskQueueSize = 200000
taskQueue := job.NewTaskQueue(ctx, progress, taskQueueSize, c.GetParallelTasksWithAutoDetection())
taskQueue := job.NewTaskQueue(ctx, progress, taskQueueSize, cfg.GetParallelTasksWithAutoDetection())

var minModTime time.Time
if j.input.Filter != nil && j.input.Filter.MinModTime != nil {
Expand All @@ -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{
Paths: paths,
ScanFilters: []file.PathFilter{newScanFilter(c, repo, minModTime)},
ZipFileExtensions: c.GetGalleryExtensions(),
ParallelTasks: c.GetParallelTasksWithAutoDetection(),
HandlerRequiredFilters: []file.Filter{newHandlerRequiredFilter(c, repo)},
ZipFileExtensions: cfg.GetGalleryExtensions(),
ParallelTasks: cfg.GetParallelTasksWithAutoDetection(),
HandlerRequiredFilters: []file.Filter{newHandlerRequiredFilter(cfg, repo)},
Rescan: j.input.Rescan,
}, progress)

taskQueue.Close()
Expand Down
13 changes: 11 additions & 2 deletions pkg/file/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ type ScanOptions struct {
HandlerRequiredFilters []Filter

ParallelTasks int

// When true files in path will be rescanned even if they haven't changed
Rescan bool
}

// Scan starts the scanning process.
Expand Down Expand Up @@ -1023,14 +1026,20 @@ func (s *scanJob) onExistingFile(ctx context.Context, f scanFile, existing model

fileModTime := f.ModTime
updated := !fileModTime.Equal(base.ModTime)
forceRescan := s.options.Rescan

if !updated {
if !updated && !forceRescan {
return s.onUnchangedFile(ctx, f, existing)
}

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.Size = f.Size
base.UpdatedAt = time.Now()
Expand Down
1 change: 1 addition & 0 deletions ui/v2.5/graphql/data/config.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ fragment ScraperSourceData on ScraperSource {

fragment ConfigDefaultSettingsData on ConfigDefaultSettingsResult {
scan {
# don't get rescan - it should never be defaulted to true
scanGenerateCovers
scanGeneratePreviews
scanGenerateImagePreviews
Expand Down
Loading