feat: wire background warming for detail sections

This commit is contained in:
2026-06-04 11:28:27 +02:00
parent 3fe1135203
commit 390f6386af
2 changed files with 26 additions and 3 deletions

View File

@@ -16,6 +16,11 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
const (
animeSectionTimeout = 12 * time.Second
watchOrderTimeout = 15 * time.Second
)
type AnimeHandler struct { type AnimeHandler struct {
svc Service svc Service
watchlistSvc domain.WatchlistService watchlistSvc domain.WatchlistService
@@ -29,6 +34,7 @@ type Service interface {
domain.AnimeDiscoverService domain.AnimeDiscoverService
domain.AnimeSearchService domain.AnimeSearchService
domain.AnimeDetailsService domain.AnimeDetailsService
WarmDetailSections(id int)
} }
func NewAnimeHandler(svc Service, watchlistSvc domain.WatchlistService) *AnimeHandler { func NewAnimeHandler(svc Service, watchlistSvc domain.WatchlistService) *AnimeHandler {
@@ -481,7 +487,7 @@ func (h *AnimeHandler) HandleAnimeDetails(c *gin.Context) {
section := c.Query("section") section := c.Query("section")
if section != "" && c.GetHeader("HX-Request") == "true" { if section != "" && c.GetHeader("HX-Request") == "true" {
sectionCtx, cancel := context.WithTimeout(c.Request.Context(), 4*time.Second) sectionCtx, cancel := context.WithTimeout(c.Request.Context(), animeSectionTimeout)
defer cancel() defer cancel()
var data any var data any
@@ -514,6 +520,13 @@ func (h *AnimeHandler) HandleAnimeDetails(c *gin.Context) {
}, },
err, err,
) )
if section == "recommendations" {
c.HTML(http.StatusOK, "anime.gohtml", gin.H{
"_fragment": "anime_recommendations_loading",
"AnimeID": id,
})
return
}
c.Status(http.StatusNoContent) c.Status(http.StatusNoContent)
return return
} }
@@ -531,6 +544,8 @@ func (h *AnimeHandler) HandleAnimeDetails(c *gin.Context) {
return return
} }
h.svc.WarmDetailSections(id)
user := server.CurrentUser(c) user := server.CurrentUser(c)
status := "" status := ""
var watchlistIDs []int64 var watchlistIDs []int64
@@ -570,7 +585,7 @@ func (h *AnimeHandler) HandleHTMLWatchOrder(c *gin.Context) {
userID := server.CurrentUserID(c) userID := server.CurrentUserID(c)
relationsCtx, cancel := context.WithTimeout(c.Request.Context(), 5*time.Second) relationsCtx, cancel := context.WithTimeout(c.Request.Context(), watchOrderTimeout)
defer cancel() defer cancel()
relations, err := h.svc.GetRelations(relationsCtx, id) relations, err := h.svc.GetRelations(relationsCtx, id)
@@ -584,7 +599,10 @@ func (h *AnimeHandler) HandleHTMLWatchOrder(c *gin.Context) {
}, },
err, err,
) )
c.Status(http.StatusNoContent) c.HTML(http.StatusOK, "anime.gohtml", gin.H{
"_fragment": "watch_order_loading",
"AnimeID": id,
})
return return
} }

View File

@@ -400,6 +400,11 @@ func (s *animeService) GetRelations(ctx context.Context, id int) ([]jikan.Relati
return s.jikan.GetFullRelations(ctx, id) return s.jikan.GetFullRelations(ctx, id)
} }
func (s *animeService) WarmDetailSections(id int) {
s.jikan.WarmAnimeRecommendations(id)
s.jikan.WarmFullRelations(id)
}
func (s *animeService) GetEpisodes(ctx context.Context, id int, page int) (jikan.EpisodesResponse, error) { func (s *animeService) GetEpisodes(ctx context.Context, id int, page int) (jikan.EpisodesResponse, error) {
return s.jikan.GetEpisodes(ctx, id, page) return s.jikan.GetEpisodes(ctx, id, page)
} }