]> git.lizzy.rs Git - go-anidb.git/commitdiff
anidb: Simplify (*AniDB).EpisodeByID()
authorDiogo Franco (Kovensky) <diogomfranco@gmail.com>
Tue, 16 Jul 2013 16:50:18 +0000 (13:50 -0300)
committerDiogo Franco (Kovensky) <diogomfranco@gmail.com>
Tue, 16 Jul 2013 16:50:18 +0000 (13:50 -0300)
Use (*Anime).EpisodeByEID() to search for the requested episode.

episodecache.go

index 3c3a91e18310d5182dbabb522b181338251acce1..cd2e4aa0c6d4a17e6d48677cb9249e2c6155e68b 100644 (file)
@@ -108,32 +108,16 @@ func (adb *AniDB) EpisodeByID(eid EID) <-chan *Episode {
                                }
                                udpDone = true
                        }
-                       a := <-adb.AnimeByID(AID(aid)) // this caches episodes...
-                       ep := eid.Episode()            // ...so this is now a cache hit
+                       a := <-adb.AnimeByID(AID(aid)) // updates the episode cache as well
+                       ep := a.EpisodeByEID(eid)
 
-                       if !ep.IsStale() {
+                       if ep != nil {
                                e = ep
                                break
                        } else {
-                               // check to see if we looked in the right AID
-                               found := false
-                               if a != nil {
-                                       for _, ep := range a.Episodes {
-                                               if eid == ep.EID {
-                                                       found = true
-                                                       break
-                                               }
-                                       }
-                               }
-
-                               // if found, then it's just that the anime is also stale (offline?)
-                               if found {
-                                       break
-                               } else {
-                                       // otherwise, the EID<->AID map broke
-                                       ok = false
-                                       cache.Delete("aid", "by-eid", eid)
-                               }
+                               // the EID<->AID map broke
+                               ok = false
+                               cache.Delete("aid", "by-eid", eid)
                        }
                }
                intentMap.NotifyClose(e, keys...)