feat: wire trending refresh task and snapshot reader

This commit is contained in:
Quick
2026-05-29 10:49:01 -04:00
parent d27f21b10f
commit 59874c717d
2 changed files with 33 additions and 5 deletions
+17
View File
@@ -1234,6 +1234,7 @@ func main() {
// Construct collection service for both the router and the collection sync scheduler.
var collectionSyncScheduler *catalog.CollectionSyncScheduler
var userCollectionScheduler *usercollections.Scheduler
var trendingRefresher *sections.TrendingRefresher
if needsWorkers && deps.DB != nil {
collectionRepo := catalog.NewLibraryCollectionRepository(deps.DB)
collItemRepo := catalog.NewItemRepository(deps.DB)
@@ -1243,6 +1244,19 @@ func main() {
deps.CollectionService = collectionService
collectionSyncScheduler = catalog.NewCollectionSyncScheduler(collectionRepo, collectionService, slog.Default())
// The trending refresher reuses the section repo (to find used source/
// window combos), a snapshot repo, an item repo (external-ID matching),
// and the TMDB fetcher. The Trakt fetcher needs settingsRepo and is
// propagated onto deps.TrendingRefresher later in router.go.
trendingRefresher = sections.NewTrendingRefresher(
sectionRepo,
sections.NewTrendingSnapshotRepository(pool),
catalog.NewItemRepository(deps.DB),
collectionService.TMDBCollections,
collectionService.TraktCollections,
)
deps.TrendingRefresher = trendingRefresher
if deps.UserStoreProvider != nil {
userSync := usercollections.NewService(deps.UserStoreProvider, collItemRepo, libraryItemRepo, nil, slog.Default())
userSync.TMDBCollections = collectionService.TMDBCollections
@@ -1287,6 +1301,9 @@ func main() {
if collectionSyncScheduler != nil {
taskMgr.Register(tasks.NewSyncCollectionsTask(collectionSyncScheduler))
}
if trendingRefresher != nil {
taskMgr.Register(tasks.NewRefreshTrendingDiscoverTask(trendingRefresher))
}
if userCollectionScheduler != nil {
taskMgr.Register(tasks.NewSyncUserCollectionsTask(userCollectionScheduler))
}
+16 -5
View File
@@ -141,6 +141,11 @@ type Dependencies struct {
UserCollectionSync *usercollections.Service
UserCollectionScheduler *usercollections.Scheduler
// TrendingRefresher refreshes the persisted trending_discover snapshots.
// Built in main.go with TMDB wired; its Trakt fetcher is propagated here in
// router.go once the Trakt adapter exists (mirrors UserCollectionSync).
TrendingRefresher *sections.TrendingRefresher
// MDBListClient is used by user-facing list discovery endpoints
// (search/top). May be nil; the handlers report "not configured" in
// that case rather than failing.
@@ -878,11 +883,17 @@ func NewRouter(deps Dependencies) chi.Router {
}
}
// Wire external-trending fetchers into the section fetcher so the
// trending_discover home section can pull TMDB/Trakt trending.
sectionFetcher.ItemRepo = itemRepo
sectionFetcher.TMDBTrending = libraryCollectionService.TMDBCollections
sectionFetcher.TraktTrending = libraryCollectionService.TraktCollections
// Propagate the now-wired Trakt fetcher to the trending refresher (built
// in main.go with TMDB only, before the Trakt adapter existed).
if deps.TrendingRefresher != nil && deps.TrendingRefresher.TraktTrending == nil {
deps.TrendingRefresher.TraktTrending = libraryCollectionService.TraktCollections
}
// Wire the trending snapshot reader into the section fetcher. The
// trending_discover home section reads its list from the persisted
// snapshot table; the upstream fetch happens out-of-band in the refresh
// task, so the read path never calls the provider.
sectionFetcher.TrendingSnapshots = sections.NewTrendingSnapshotRepository(deps.DB)
libraryCollectionHandler = handlers.NewLibraryCollectionHandler(
libraryCollectionRepo,