]> git.lizzy.rs Git - go-anidb.git/commitdiff
anidb: Cache finished anime for longer
authorDiogo Franco (Kovensky) <diogomfranco@gmail.com>
Tue, 16 Jul 2013 17:05:13 +0000 (14:05 -0300)
committerDiogo Franco (Kovensky) <diogomfranco@gmail.com>
Tue, 16 Jul 2013 17:05:13 +0000 (14:05 -0300)
Once they've finished airing, it's more unlikely they'll get updates. We
only consider they as finished if they were cached more than one
AnimeCacheDuration after the end though.

animecache.go
misc.go

index fd2d7f3d507613a09630fcd26054685ade5b117d..25624fb8d0cf2ffaf8af054ee5262b4e63f2b3ef 100644 (file)
@@ -26,10 +26,17 @@ func (a *Anime) IsStale() bool {
        if a == nil {
                return true
        }
+       now := time.Now()
+       diff := now.Sub(a.Cached)
        if a.Incomplete {
-               return time.Now().Sub(a.Cached) > AnimeIncompleteCacheDuration
+               return diff > AnimeIncompleteCacheDuration
        }
-       return time.Now().Sub(a.Cached) > AnimeCacheDuration
+
+       // If the anime ended, and more than AnimeCacheDuration time ago at that
+       if !a.EndDate.IsZero() && now.After(a.EndDate.Add(AnimeCacheDuration)) {
+               return diff > FinishedAnimeCacheDuration
+       }
+       return diff > AnimeCacheDuration
 }
 
 // Unique Anime IDentifier.
diff --git a/misc.go b/misc.go
index 22a010c1d2b7412a92dec55c19702b16bd778ecd..b6d9db828c46e977d8ff0954b393f30fd6672275 100644 (file)
--- a/misc.go
+++ b/misc.go
@@ -15,6 +15,10 @@ var (
        GroupCacheDuration   = 4 * DefaultCacheDuration // They don't change that often.
        FileCacheDuration    = 8 * DefaultCacheDuration // These change even less often.
 
+       // Used for anime that have already finished airing.
+       // It's unlikely that they get any important updates.
+       FinishedAnimeCacheDuration = 4 * AnimeCacheDuration
+
        // Used when a request uses a non-existing key (AID, ed2k+size, etc)
        InvalidKeyCacheDuration = 1 * time.Hour