diff --git a/anilist.go b/anilist.go index 1d72715..201bae2 100644 --- a/anilist.go +++ b/anilist.go @@ -5,7 +5,6 @@ import ( "git.milar.in/milarin/anilist" "git.milar.in/milarin/channel" - "git.milar.in/nyaanime/model" ) func GetAnimeListByAnimeID(statuses []anilist.MediaListStatus) (map[anilist.MediaID]*anilist.MediaList, error) { @@ -40,15 +39,19 @@ func GetCurrentlyWatchingAnimesContext(ctx context.Context, statuses ...anilist. } var ( - animeByTitleCache = map[string]model.Pair[*anilist.Media, error]{} + animeByTitleCache = map[string]*anilist.Media{} ) func SearchAnimeByTitle(title string) (anime *anilist.Media, err error) { // caching if cacheEntry, ok := animeByTitleCache[title]; ok { - return cacheEntry.First, cacheEntry.Second + return cacheEntry, nil } - defer func() { animeByTitleCache[title] = model.Pair[*anilist.Media, error]{First: anime, Second: err} }() + defer func() { + if err != nil && anime != nil { + animeByTitleCache[title] = anime + } + }() token, err := GetAnilistAccessToken() if err != nil {