From 1dea35b9bcb3d37d61e554a99488626da9795331 Mon Sep 17 00:00:00 2001 From: Gabriel Arakaki Giovanini Date: Fri, 23 Jun 2023 21:25:37 +0200 Subject: feat: Remove unecessary param from repo --- pkg/database/sql/media.go | 2 +- pkg/worker/exif_scanner.go | 2 +- pkg/worker/file_scanner.go | 6 ++++++ pkg/worker/list_processor_test.go | 2 +- pkg/worker/worker.go | 4 ++-- 5 files changed, 11 insertions(+), 5 deletions(-) (limited to 'pkg') diff --git a/pkg/database/sql/media.go b/pkg/database/sql/media.go index 835e262..59a4b83 100644 --- a/pkg/database/sql/media.go +++ b/pkg/database/sql/media.go @@ -223,7 +223,7 @@ func (r *MediaRepository) GetEmptyEXIF(ctx context.Context, pagination *media.Pa Where("media_exifs.media_id IS NULL"). Offset(pagination.Page * pagination.Size). Limit(pagination.Size). - Order("created_at DESC"). + Order("media.created_at DESC"). Find(&medias) if result.Error != nil { diff --git a/pkg/worker/exif_scanner.go b/pkg/worker/exif_scanner.go index 66091cd..6d40dbd 100644 --- a/pkg/worker/exif_scanner.go +++ b/pkg/worker/exif_scanner.go @@ -15,7 +15,7 @@ type ( var _ ListProcessor[*media.Media] = &EXIFScanner{} -func NewEXIFScanner(root string, repository media.Repository) *EXIFScanner { +func NewEXIFScanner(repository media.Repository) *EXIFScanner { return &EXIFScanner{ repository: repository, } diff --git a/pkg/worker/file_scanner.go b/pkg/worker/file_scanner.go index 321fbca..0dc2eb2 100644 --- a/pkg/worker/file_scanner.go +++ b/pkg/worker/file_scanner.go @@ -33,6 +33,12 @@ func (f *FileScanner) Query(ctx context.Context) (<-chan string, error) { go func() { defer close(c) _ = filepath.Walk(f.root, func(path string, info fs.FileInfo, err error) error { + select { + case <-ctx.Done(): + return filepath.SkipAll + default: + } + if info.IsDir() && filepath.Base(info.Name())[0] == '.' { return filepath.SkipDir } diff --git a/pkg/worker/list_processor_test.go b/pkg/worker/list_processor_test.go index b7373d1..1e4ed2d 100644 --- a/pkg/worker/list_processor_test.go +++ b/pkg/worker/list_processor_test.go @@ -1,4 +1,4 @@ -// go:build unit +//go:build unit package worker diff --git a/pkg/worker/worker.go b/pkg/worker/worker.go index c52f0be..18cc0e2 100644 --- a/pkg/worker/worker.go +++ b/pkg/worker/worker.go @@ -36,12 +36,12 @@ func (self *WorkerPool) AddWorker(name string, worker Worker) { } func (self *WorkerPool) Start(ctx context.Context) { + self.wg.Add(len(self.workers)) for _, w := range self.workers { - self.wg.Add(1) go func(w *Work) { defer self.wg.Done() if err := w.Worker.Start(ctx); err != nil && !errors.Is(err, context.Canceled) { - fmt.Println("Error ", w.Name, err.Error()) + fmt.Println("Processes finished, error", w.Name, err.Error()) } else { fmt.Println(w.Name, "done") } -- cgit v1.2.3