fixed anime not found error when torrent sites are faster than anilist API in adding new animes
This commit is contained in:
parent
da15313c21
commit
93bc926c34
11
anilist.go
11
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user