Handle bundled collection poster failures gracefully

- Log poster store/update failures instead of aborting collection sync
- Preallocate matched collection replacements using the active limit
This commit is contained in:
Silo Server Migration
2026-05-23 21:32:22 -04:00
parent 0d1f40f8c4
commit 4c2fcdfff0
3 changed files with 37 additions and 6 deletions
+15 -2
View File
@@ -130,7 +130,14 @@ func (h *LibraryCollectionHandler) storeBundledTemplatePoster(
posterPath,
)
if err != nil || !stored {
return false, storedPath, thumbhash, err
if err != nil {
slog.Warn("failed to store bundled template poster",
"collection_id", collectionID,
"poster_path", posterPath,
"error", err,
)
}
return false, storedPath, thumbhash, nil
}
notAutoGenerated := false
@@ -144,7 +151,13 @@ func (h *LibraryCollectionHandler) storeBundledTemplatePoster(
input.PosterFromTemplate = &fromTemplate
}
if err := h.repo.Update(ctx, input); err != nil {
return false, "", "", fmt.Errorf("updating bundled poster path: %w", err)
slog.Warn("failed to persist bundled template poster",
"collection_id", collectionID,
"poster_path", posterPath,
"stored_path", storedPath,
"error", err,
)
return false, "", "", nil
}
return true, storedPath, thumbhash, nil
}
@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io/fs"
"log/slog"
"net/http"
"strings"
"time"
@@ -270,7 +271,14 @@ func (h *UserCollectionImportHandler) storeBundledTemplatePoster(
posterPath,
)
if err != nil || !stored {
return err
if err != nil {
slog.Warn("failed to store bundled user collection poster",
"collection_id", collection.ID,
"poster_path", posterPath,
"error", err,
)
}
return nil
}
if err := store.UpdateCollection(r.Context(), userstore.UpdateCollectionInput{
@@ -279,7 +287,13 @@ func (h *UserCollectionImportHandler) storeBundledTemplatePoster(
PosterURL: &storedPath,
PosterThumbhash: &thumbhash,
}); err != nil {
return fmt.Errorf("persisting template poster: %w", err)
slog.Warn("failed to persist bundled user collection poster",
"collection_id", collection.ID,
"poster_path", posterPath,
"stored_path", storedPath,
"error", err,
)
return nil
}
collection.PosterURL = storedPath
collection.PosterThumbhash = thumbhash
+6 -2
View File
@@ -243,8 +243,12 @@ func (s *Service) filterByLibraries(ctx context.Context, matched []userstore.Col
// content_id for each, and produces deduped, position-numbered replacements
// plus an unmatched count. Shared by all three source backends.
func resolveMatchedWithLimit(total int, limit *int, resolve func(i int) string) ([]userstore.CollectionItemReplacement, int, int) {
matched := make([]userstore.CollectionItemReplacement, 0, total)
seen := make(map[string]struct{}, total)
capacity := total
if limit != nil && *limit > 0 && *limit < total {
capacity = *limit
}
matched := make([]userstore.CollectionItemReplacement, 0, capacity)
seen := make(map[string]struct{}, capacity)
unmatched := 0
scanned := 0
for i := 0; i < total; i++ {