]> git.lizzy.rs Git - go-anidb.git/blobdiff - animecache.go
anidb: Log UDP traffic
[go-anidb.git] / animecache.go
index 91a8c41022fe8c9611acc92c13e1f0f6ede86525..99b89015081833512858db5923f88c6d9bc93429 100644 (file)
@@ -53,12 +53,17 @@ type httpAnimeResponse struct {
        err   error
 }
 
-// Retrieves an Anime by its AID. Uses both HTTP and UDP APIs,
+// Retrieves an Anime by its AID. Uses both the HTTP and UDP APIs,
 // but can work without the UDP API.
 func (adb *AniDB) AnimeByID(aid AID) <-chan *Anime {
        keys := []cacheKey{"aid", aid}
        ch := make(chan *Anime, 1)
 
+       if aid < 1 {
+               ch <- nil
+               close(ch)
+       }
+
        ic := make(chan Cacheable, 1)
        go func() { ch <- (<-ic).(*Anime); close(ch) }()
        if intentMap.Intent(ic, keys...) {
@@ -66,13 +71,13 @@ func (adb *AniDB) AnimeByID(aid AID) <-chan *Anime {
        }
 
        if !cache.CheckValid(keys...) {
-               intentMap.Notify((*Anime)(nil), keys...)
+               intentMap.NotifyClose((*Anime)(nil), keys...)
                return ch
        }
 
        anime := aid.Anime()
        if !anime.IsStale() {
-               intentMap.Notify(anime, keys...)
+               intentMap.NotifyClose(anime, keys...)
                return ch
        }
 
@@ -141,9 +146,9 @@ func (adb *AniDB) AnimeByID(aid AID) <-chan *Anime {
                        if ok {
                                cache.Set(anime, keys...)
                        }
-                       intentMap.Notify(anime, keys...)
+                       intentMap.NotifyClose(anime, keys...)
                } else {
-                       intentMap.Notify((*Anime)(nil), keys...)
+                       intentMap.NotifyClose((*Anime)(nil), keys...)
                }
        }()
        return ch
@@ -227,7 +232,7 @@ func (a *Anime) populateFromHTTP(reply httpapi.Anime) bool {
                        titles[Language(title.Lang)] = title.Title
                }
 
-               e := Episode{
+               e := &Episode{
                        EID: EID(ep.ID),
                        AID: a.AID,
 
@@ -243,12 +248,12 @@ func (a *Anime) populateFromHTTP(reply httpapi.Anime) bool {
                        Titles: titles,
                }
                counts[e.Type]++
-               cacheEpisode(&e)
+               cacheEpisode(e)
 
                a.Episodes = append(a.Episodes, e)
        }
 
-       a.EpisodeCount = EpisodeCount{
+       a.EpisodeCount = misc.EpisodeCount{
                RegularCount: counts[misc.EpisodeTypeRegular],
                SpecialCount: counts[misc.EpisodeTypeSpecial],
                CreditsCount: counts[misc.EpisodeTypeCredits],