refactor(services): replace temporary variable pointer pattern with new() builtin

Simplify pointer creation in media scanner validation messages and worker
job timestamps by using inline new() instead of local variable + address-of.

In media_scanner.go this cleans up three validation error message returns
(manga/comics library format checks). In worker.go it simplifies StartedAt
and CompletedAt timestamp assignments.
This commit is contained in:
2026-04-20 08:58:19 -04:00
parent 9b141d75e8
commit 2b139afce6
2 changed files with 8 additions and 13 deletions
+6 -9
View File
@@ -1297,13 +1297,12 @@ func (s *MediaScanner) ValidateMediaItemForLibrary(
// Must be fixed-layout or comic archive // Must be fixed-layout or comic archive
if mediaItem.FormatGroup != "fixed_layout" && if mediaItem.FormatGroup != "fixed_layout" &&
mediaItem.FormatGroup != "comic_archive" { mediaItem.FormatGroup != "comic_archive" {
msg := fmt.Sprintf( return new(fmt.Sprintf(
"EPUB file '%s' is reflowable (text-based), not fixed-layout (image-based). "+ "EPUB file '%s' is reflowable (text-based), not fixed-layout (image-based). "+
"Manga library only accepts fixed-layout EPUBs, CBZ, CBR, or image files. "+ "Manga library only accepts fixed-layout EPUBs, CBZ, CBR, or image files. "+
"Consider moving this file to an ebooks library.", "Consider moving this file to an ebooks library.",
mediaItem.Title, mediaItem.Title,
) ))
return &msg
} }
// Set manga-specific flags for fixed-layout EPUBs // Set manga-specific flags for fixed-layout EPUBs
@@ -1328,12 +1327,11 @@ func (s *MediaScanner) ValidateMediaItemForLibrary(
// Accept comic archives and fixed-layout // Accept comic archives and fixed-layout
if mediaItem.FormatGroup != "comic_archive" && if mediaItem.FormatGroup != "comic_archive" &&
mediaItem.FormatGroup != "fixed_layout" { mediaItem.FormatGroup != "fixed_layout" {
msg := fmt.Sprintf( return new(fmt.Sprintf(
"File '%s' is not a comic archive format. "+ "File '%s' is not a comic archive format. "+
"Comics library only accepts CBZ, CBR, CB7, CBT, PDF, or fixed-layout EPUBs.", "Comics library only accepts CBZ, CBR, CB7, CBT, PDF, or fixed-layout EPUBs.",
mediaItem.Title, mediaItem.Title,
) ))
return &msg
} }
} }
@@ -1342,12 +1340,11 @@ func (s *MediaScanner) ValidateMediaItemForLibrary(
// Flag manga for potential reorganization (info level) // Flag manga for potential reorganization (info level)
if mediaItem.FormatGroup == "fixed_layout" && if mediaItem.FormatGroup == "fixed_layout" &&
(!mediaItem.MangaType.Valid || mediaItem.MangaType.String == "yes" || mediaItem.MangaType.String == "yes_and_right_to_left") { (!mediaItem.MangaType.Valid || mediaItem.MangaType.String == "yes" || mediaItem.MangaType.String == "yes_and_right_to_left") {
msg := fmt.Sprintf( return new(fmt.Sprintf(
"File '%s' appears to be manga (fixed-layout with images). "+ "File '%s' appears to be manga (fixed-layout with images). "+
"Consider moving to a manga or comics library for better organization.", "Consider moving to a manga or comics library for better organization.",
mediaItem.Title, mediaItem.Title,
) ))
return &msg
} }
} }
+2 -4
View File
@@ -221,8 +221,7 @@ func (w *Worker) processJob(job *Job) {
} }
w.mu.Unlock() w.mu.Unlock()
now := time.Now() job.StartedAt = new(time.Now())
job.StartedAt = &now
w.mu.Lock() w.mu.Lock()
if result, exists := w.results[job.ID]; exists { if result, exists := w.results[job.ID]; exists {
@@ -254,8 +253,7 @@ func (w *Worker) processJob(job *Job) {
err = fmt.Errorf("unknown job type: %s", job.Type) err = fmt.Errorf("unknown job type: %s", job.Type)
} }
completedAt := time.Now() job.CompletedAt = new(time.Now())
job.CompletedAt = &completedAt
job.Error = err job.Error = err
job.Result = result job.Result = result