perf: reduce watch progress saves and cache anime API responses

This commit is contained in:
2026-04-26 18:46:54 +02:00
parent df9309282b
commit d6457541ce
4 changed files with 22 additions and 18 deletions

View File

@@ -265,6 +265,9 @@ func (h *Handler) HandleAPIAnime(w http.ResponseWriter, r *http.Request) {
}
statuses := h.watchlistMap(r.Context(), userIDFromRequest(r))
w.Header().Set("Cache-Control", "public, max-age=3600")
switch section {
case "relations":
relations, err := h.jikanClient.GetFullRelations(r.Context(), id)
@@ -313,15 +316,14 @@ func (h *Handler) HandleAPIAnime(w http.ResponseWriter, r *http.Request) {
func (h *Handler) HandleAPIEpisodes(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path[len("/api/episodes/"):]
path = strings.Trim(path, "/")
id, err := strconv.Atoi(path)
if err != nil || id <= 0 {
http.Error(w, "invalid id", http.StatusBadRequest)
return
}
currentEpisode := r.URL.Query().Get("current")
w.Header().Set("Cache-Control", "public, max-age=3600")
episodes, err := h.getEpisodes(r.Context(), id)
if err != nil {
log.Printf("episodes error: %v", err)

View File

@@ -388,21 +388,21 @@ func (h *Handler) HandleEpisodeData(w http.ResponseWriter, r *http.Request) {
token = source.Token
}
response := struct {
MalID int `json:"mal_id"`
Title string `json:"title"`
CurrentEpisode string `json:"current_episode"`
TotalEpisodes int `json:"total_episodes"`
InitialMode string `json:"initial_mode"`
Token string `json:"token"`
AvailableModes []string `json:"available_modes"`
ModeSources map[string]shared.ModeSource `json:"mode_sources"`
Segments []shared.SkipSegment `json:"segments"`
response := struct {
MalID int `json:"mal_id"`
Title string `json:"title"`
CurrentEpisode string `json:"current_episode"`
TotalEpisodes int `json:"total_episodes"`
InitialMode string `json:"initial_mode"`
Token string `json:"token"`
AvailableModes []string `json:"available_modes"`
ModeSources map[string]shared.ModeSource `json:"mode_sources"`
Segments []shared.SkipSegment `json:"segments"`
}{
MalID: malID,
MalID: malID,
Title: data.Title,
CurrentEpisode: data.CurrentEpisode,
TotalEpisodes: anime.Episodes,
TotalEpisodes: anime.Episodes,
InitialMode: initialMode,
Token: token,
AvailableModes: data.AvailableModes,