refactor: shorten verbose variable names across codebase
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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:]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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{},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user