From 71798bcbabf1a5739a7e9ca810ded443abfd45ce Mon Sep 17 00:00:00 2001 From: SCDevel <32443069+SCDevel@users.noreply.github.com> Date: Wed, 4 Mar 2026 21:28:39 -0800 Subject: [PATCH] Run auto-tagging only if no documents found by OCR This is to help prevent a task-switching overhead that comes from the potentially long startup times of models. --- background.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/background.go b/background.go index 6b002d87..19e2f505 100644 --- a/background.go +++ b/background.go @@ -46,11 +46,14 @@ func StartBackgroundTasks(ctx context.Context, app BackgroundProcessor) { } // Run auto-tagging after OCR - autoCount, err := app.processAutoTagDocuments(ctx) - if err != nil { - return 0, fmt.Errorf("error in processAutoTagDocuments: %w", err) + // Only run auto-tagging if OCR did not find any documents to process, otherwise re-run OCR + if count == 0 { + autoCount, err := app.processAutoTagDocuments(ctx) + if err != nil { + return 0, fmt.Errorf("error in processAutoTagDocuments: %w", err) + } + count += autoCount } - count += autoCount return count, nil }()