From 35154763743a63b03e43445a4595aa469e413eb2 Mon Sep 17 00:00:00 2001 From: mkelvers Date: Tue, 23 Jun 2026 17:23:27 +0200 Subject: [PATCH] refactor: shorten verbose variable names across codebase --- integrations/jikan/relations.go | 6 +++--- integrations/playback/allanime/extractor.go | 6 +++--- integrations/playback/allanime/search.go | 8 ++++---- integrations/playback/allanime/sources.go | 2 +- integrations/watchorder/watch_order.go | 4 ++-- internal/anime/details_handler.go | 6 +++--- internal/anime/recommendations/rerank.go | 14 +++++++------- internal/anime/recommendations/scoring.go | 18 +++++++++--------- internal/anime/recommendations/store.go | 6 +++--- internal/episodes/service/service.go | 4 ++-- internal/observability/log_test.go | 4 ++-- internal/playback/watch_data.go | 15 ++++++++------- 12 files changed, 47 insertions(+), 46 deletions(-) diff --git a/integrations/jikan/relations.go b/integrations/jikan/relations.go index f097bf2..769fdbe 100644 --- a/integrations/jikan/relations.go +++ b/integrations/jikan/relations.go @@ -195,7 +195,7 @@ func buildAllowedWatchOrderEntries(result watchorder.WatchOrderResult, mode Watc break } } - shouldIncludeAllTypes := mode == WatchOrderModeComplete || !hasTVEntry + allTypes := mode == WatchOrderModeComplete || !hasTVEntry for _, entry := range result.WatchOrder { if len(allowedEntries) >= maxWatchOrderEntries { @@ -204,8 +204,8 @@ func buildAllowedWatchOrderEntries(result watchorder.WatchOrderResult, mode Watc if seen[entry.ID] { continue } - normalizedType := strings.ToLower(strings.TrimSpace(entry.Type)) - if !shouldIncludeAllTypes && normalizedType != "tv" && normalizedType != "movie" { + typ := strings.ToLower(strings.TrimSpace(entry.Type)) + if !allTypes && typ != "tv" && typ != "movie" { continue } diff --git a/integrations/playback/allanime/extractor.go b/integrations/playback/allanime/extractor.go index dae0d3e..e851875 100644 --- a/integrations/playback/allanime/extractor.go +++ b/integrations/playback/allanime/extractor.go @@ -293,13 +293,13 @@ func parseM3U8Sources(body string, masterURL string, referer string) []StreamSou lines := strings.Split(body, "\n") baseURL := playlistBaseURL(masterURL) bwPattern := regexp.MustCompile(`BANDWIDTH=(\d+)`) - currentBandwidth := 0 + bw := 0 sources := make([]StreamSource, 0) for _, line := range lines { trimmed := strings.TrimSpace(line) if bandwidth, ok := parseStreamBandwidth(trimmed, bwPattern); ok { - currentBandwidth = bandwidth + bw = bandwidth continue } if trimmed == "" || strings.HasPrefix(trimmed, "#") { @@ -313,7 +313,7 @@ func parseM3U8Sources(body string, masterURL string, referer string) []StreamSou sources = append(sources, StreamSource{ URL: streamURL, - Quality: qualityFromBandwidth(currentBandwidth), + Quality: qualityFromBandwidth(bw), Provider: "hls", Type: "m3u8", Referer: referer, diff --git a/integrations/playback/allanime/search.go b/integrations/playback/allanime/search.go index 17b88bc..f6ded3b 100644 --- a/integrations/playback/allanime/search.go +++ b/integrations/playback/allanime/search.go @@ -101,7 +101,7 @@ func (c *AllAnimeProvider) Search(ctx context.Context, query string, mode string func (c *AllAnimeProvider) resolveShowIDWithFallback(ctx context.Context, animeID int, titleCandidates []string, mode string) string { targetMalIDStr := strconv.Itoa(animeID) - firstAvailableShowID := "" + fallbackID := "" for _, title := range titleCandidates { searchResults, err := c.Search(ctx, title, mode) @@ -111,12 +111,12 @@ func (c *AllAnimeProvider) resolveShowIDWithFallback(ctx context.Context, animeI if showID := exactMatchShowID(searchResults, targetMalIDStr); showID != "" { return showID } - if firstAvailableShowID == "" { - firstAvailableShowID = searchResults[0].ID + if fallbackID == "" { + fallbackID = searchResults[0].ID } } - return firstAvailableShowID + return fallbackID } func exactMatchShowID(searchResults []searchResult, targetMalID string) string { diff --git a/integrations/playback/allanime/sources.go b/integrations/playback/allanime/sources.go index f7e0a39..f1f0096 100644 --- a/integrations/playback/allanime/sources.go +++ b/integrations/playback/allanime/sources.go @@ -212,7 +212,7 @@ func buildSourceReferences(rawSourceURLs []any) []sourceReference { ref := sourceReference{URL: sourceURL, Name: sourceName} normalized := strings.ToLower(sourceName) - if _, prioritizedProvider := prioritySet[normalized]; prioritizedProvider { + if _, priority := prioritySet[normalized]; priority { if _, exists := prioritized[normalized]; !exists { prioritized[normalized] = ref } diff --git a/integrations/watchorder/watch_order.go b/integrations/watchorder/watch_order.go index 36a6a38..a2eff7a 100644 --- a/integrations/watchorder/watch_order.go +++ b/integrations/watchorder/watch_order.go @@ -156,13 +156,13 @@ func extractRows(doc *goquery.Document) []watchOrderRow { } title := strings.TrimSpace(selection.Find(".wo_title").First().Text()) - alternativeTitle := strings.TrimSpace(selection.Find(".uk-text-small").First().Text()) + alt := strings.TrimSpace(selection.Find(".uk-text-small").First().Text()) rows = append(rows, watchOrderRow{ id: id, typeID: typeID, title: title, - alternativeTitle: alternativeTitle, + alternativeTitle: alt, }) }) diff --git a/internal/anime/details_handler.go b/internal/anime/details_handler.go index 9fe8bf7..5a331cc 100644 --- a/internal/anime/details_handler.go +++ b/internal/anime/details_handler.go @@ -317,13 +317,13 @@ func (h *AnimeHandler) HandleHTMLWatchOrder(c *gin.Context) { return } - relationAnimeIDs := make([]int64, 0, len(relations)) + ids := make([]int64, 0, len(relations)) for _, relation := range relations { if relation.Anime.MalID > 0 { - relationAnimeIDs = append(relationAnimeIDs, int64(relation.Anime.MalID)) + ids = append(ids, int64(relation.Anime.MalID)) } } - watchlistMap := h.watchlistMapForIDs(c.Request.Context(), userID, relationAnimeIDs) + watchlistMap := h.watchlistMapForIDs(c.Request.Context(), userID, ids) c.HTML(http.StatusOK, "anime.gohtml", gin.H{ "_fragment": "watch_order", diff --git a/internal/anime/recommendations/rerank.go b/internal/anime/recommendations/rerank.go index f509c9e..1032b74 100644 --- a/internal/anime/recommendations/rerank.go +++ b/internal/anime/recommendations/rerank.go @@ -10,11 +10,11 @@ import ( func rerankRecommendationCandidates(candidates []recommendationCandidate, limit int) []domain.Anime { selected := make([]domain.Anime, 0, min(limit, len(candidates))) remaining := slices.Clone(candidates) - seenFeatures := newDiversityFeatureCounts() - recentFeatures := make([]diversityFeatureSet, 0, recentDiversityWindow) + seen := newDiversityFeatureCounts() + recent := make([]diversityFeatureSet, 0, recentDiversityWindow) for len(selected) < limit && len(remaining) > 0 { - bestIndex := bestDiverseCandidateIndex(remaining, seenFeatures, recentFeatures) + bestIndex := bestDiverseCandidateIndex(remaining, seen, recent) candidate := remaining[bestIndex] remaining = slices.Delete(remaining, bestIndex, bestIndex+1) @@ -26,10 +26,10 @@ func rerankRecommendationCandidates(candidates []recommendationCandidate, limit selected = append(selected, domain.Anime{Anime: candidate.anime}) features := diversityFeatures(candidate.anime) - seenFeatures.add(features) - recentFeatures = append(recentFeatures, features) - if len(recentFeatures) > recentDiversityWindow { - recentFeatures = recentFeatures[1:] + seen.add(features) + recent = append(recent, features) + if len(recent) > recentDiversityWindow { + recent = recent[1:] } } diff --git a/internal/anime/recommendations/scoring.go b/internal/anime/recommendations/scoring.go index e646977..ed12023 100644 --- a/internal/anime/recommendations/scoring.go +++ b/internal/anime/recommendations/scoring.go @@ -29,25 +29,25 @@ func scoreRecommendationCandidate( collaborativeScore float64, profileSearchScore float64, ) recommendationCandidate { - genreMatches, genreScore := weightedEntityMatch(profile.genres, candidate.Genres) - themeMatches, themeScore := weightedEntityMatch(profile.themes, candidate.Themes) - studioMatches, studioScore := weightedEntityMatch(profile.studios, candidate.Studios) - demographicMatches, demographicScore := weightedEntityMatch(profile.demographics, candidate.Demographics) + genres, genreScore := weightedEntityMatch(profile.genres, candidate.Genres) + themes, themeScore := weightedEntityMatch(profile.themes, candidate.Themes) + studios, studioScore := weightedEntityMatch(profile.studios, candidate.Studios) + demos, demoScore := weightedEntityMatch(profile.demographics, candidate.Demographics) score := rankedCandidateRetrievalScore(collaborativeScore, profileSearchScore) score += genreScore * genreMatchWeight score += themeScore * themeMatchWeight score += studioScore * studioMatchWeight - score += demographicScore * demographicMatchWeight + score += demoScore * demographicMatchWeight score += recommendationCandidateScoreAdjustments(now, profile, candidate) return recommendationCandidate{ anime: candidate, score: score, - genreMatches: genreMatches, - themeMatches: themeMatches, - studioMatches: studioMatches, - demographicMatches: demographicMatches, + genreMatches: genres, + themeMatches: themes, + studioMatches: studios, + demographicMatches: demos, } } diff --git a/internal/anime/recommendations/store.go b/internal/anime/recommendations/store.go index 27bb34e..7ddd6aa 100644 --- a/internal/anime/recommendations/store.go +++ b/internal/anime/recommendations/store.go @@ -13,16 +13,16 @@ type candidateStore struct { } func newCandidateStore(watchlist []db.GetUserWatchListRow) *candidateStore { - watchlistAnimeIDs := make(map[int]struct{}, len(watchlist)) + watched := make(map[int]struct{}, len(watchlist)) for _, entry := range watchlist { if entry.AnimeID <= 0 { continue } - watchlistAnimeIDs[int(entry.AnimeID)] = struct{}{} + watched[int(entry.AnimeID)] = struct{}{} } return &candidateStore{ - watchlistAnimeIDs: watchlistAnimeIDs, + watchlistAnimeIDs: watched, byID: map[int]rankedCandidate{}, } } diff --git a/internal/episodes/service/service.go b/internal/episodes/service/service.go index fb8bd53..1b43db7 100644 --- a/internal/episodes/service/service.go +++ b/internal/episodes/service/service.go @@ -138,7 +138,7 @@ func (s *EpisodeService) refresh(ctx context.Context, anime domain.Anime) (domai ) } - providerAvailability, source, providerErr := s.fetchProviderAvailability(ctx, anime) + availability, source, providerErr := s.fetchProviderAvailability(ctx, anime) if providerErr != nil { s.markFailure(ctx, anime, providerErr) if cached, ok := s.getDecodedCached(ctx, anime); ok { @@ -165,7 +165,7 @@ func (s *EpisodeService) refresh(ctx context.Context, anime domain.Anime) (domai return domain.CanonicalEpisodeList{}, providerErr } - return s.store(ctx, anime, jikanEpisodes, providerAvailability, source, now, true) + return s.store(ctx, anime, jikanEpisodes, availability, source, now, true) } func (s *EpisodeService) fetchProviderAvailability(ctx context.Context, anime domain.Anime) (domain.EpisodeAvailability, string, error) { diff --git a/internal/observability/log_test.go b/internal/observability/log_test.go index 66db046..90ef625 100644 --- a/internal/observability/log_test.go +++ b/internal/observability/log_test.go @@ -36,10 +36,10 @@ func TestFormatLogEntryFormatsHTTPRequestCompactly(t *testing.T) { } func TestFormatHTTPStatusColorsByStatusFamily(t *testing.T) { - previousColorLogs := colorLogs + prev := colorLogs colorLogs = true t.Cleanup(func() { - colorLogs = previousColorLogs + colorLogs = prev }) tests := map[any]string{ diff --git a/internal/playback/watch_data.go b/internal/playback/watch_data.go index b6b8106..2ae495b 100644 --- a/internal/playback/watch_data.go +++ b/internal/playback/watch_data.go @@ -26,18 +26,19 @@ func (s *playbackService) BuildWatchData(ctx context.Context, animeID int, title ) } searchTitles := buildSearchTitles(animeData, titleCandidates) - canonicalEpisodes, err := s.episodes.GetCanonicalEpisodes(ctx, animeData, false) + eps, err := s.episodes.GetCanonicalEpisodes(ctx, animeData, false) if err != nil { return domain.WatchPageData{}, fmt.Errorf("failed to fetch episodes: %w", err) } - mode, modeSwitchedFrom := resolveMode(episode, mode, canonicalEpisodes.Episodes) - modeSources, result, resolvedMode, resolvedModeSwitchedFrom := s.resolveModeSources(ctx, animeID, searchTitles, episode, mode) + // mode fallback + mode, from := resolveMode(episode, mode, eps.Episodes) + modeSources, result, resolvedMode, switchedFrom := s.resolveModeSources(ctx, animeID, searchTitles, episode, mode) if resolvedMode != "" { mode = resolvedMode } - if resolvedModeSwitchedFrom != "" { - modeSwitchedFrom = resolvedModeSwitchedFrom + if switchedFrom != "" { + from = switchedFrom } startTime, watchlistStatus, watchlistIDs := s.loadWatchProgress(ctx, userID, animeID, anime.Episodes, episode) seasons := s.loadSeasons(ctx, animeID) @@ -48,8 +49,8 @@ func (s *playbackService) BuildWatchData(ctx context.Context, animeID int, title err, ) } - watchData := buildWatchDataPayload(animeData, animeID, episode, startTime, canonicalEpisodes.Episodes, modeSources, mode, modeSwitchedFrom, segments) - pageData := buildWatchPageData(animeData, canonicalEpisodes.Episodes, episode, watchlistStatus, watchlistIDs, seasons, watchData) + watchData := buildWatchDataPayload(animeData, animeID, episode, startTime, eps.Episodes, modeSources, mode, from, segments) + pageData := buildWatchPageData(animeData, eps.Episodes, episode, watchlistStatus, watchlistIDs, seasons, watchData) if len(modeSources) == 0 { return pageData, fmt.Errorf("no streams found") }