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 {
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"
@ -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"

View File

@ -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

View File

@ -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) {
@ -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 {
@ -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()

View File

@ -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.
@ -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()

View File

@ -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