From 93bc926c34343513f1192a4f1c6a1e540c658ed5 Mon Sep 17 00:00:00 2001 From: milarin Date: Fri, 3 Mar 2023 09:52:42 +0100 Subject: [PATCH] fixed anime not found error when torrent sites are faster than anilist API in adding new animes --- anilist.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 {