]> git.lizzy.rs Git - go-anidb.git/commitdiff
anime: Make cached Anime expire earlier if they're Incomplete
authorDiogo Franco (Kovensky) <diogomfranco@gmail.com>
Sun, 14 Jul 2013 18:01:38 +0000 (15:01 -0300)
committerDiogo Franco (Kovensky) <diogomfranco@gmail.com>
Sun, 14 Jul 2013 18:01:38 +0000 (15:01 -0300)
anime.go
animecache.go
misc.go

index b57fc0bd560128b67d46b0023183d57697d949f3..a8873b24759e15f20e41cfc750d9cd0affc01022 100644 (file)
--- a/anime.go
+++ b/anime.go
@@ -75,9 +75,9 @@ type Anime struct {
        Awards    []string
        Resources Resources
 
-       Incomplete bool      // Set if the only the UDP API part of the  query failed
-       Updated    time.Time // When the data was last modified in the server
-       Cached     time.Time // When the data was retrieved from the server
+       Incomplete bool      // Set if the UDP API part of the query failed.
+       Updated    time.Time // When the data was last modified in the server.
+       Cached     time.Time // When the data was retrieved from the server.
 }
 
 type EpisodeCount struct {
index ad44bfa6f3ebef7d39ec8578d67ca91dc5c6493c..e9910c553524548a09db8497a92903afe1cb03c9 100644 (file)
@@ -24,6 +24,9 @@ func (a *Anime) IsStale() bool {
        if a == nil {
                return true
        }
+       if a.Incomplete {
+               return time.Now().Sub(a.Cached) > AnimeIncompleteCacheDuration
+       }
        return time.Now().Sub(a.Cached) > AnimeCacheDuration
 }
 
diff --git a/misc.go b/misc.go
index 8cab28f1328c238ee6581e4bea9aae4e4d0ec6a3..ad8c51740516d52359c3f5e949288528dd7bcdeb 100644 (file)
--- a/misc.go
+++ b/misc.go
@@ -15,6 +15,9 @@ var (
        GroupCacheDuration   = 4 * DefaultCacheDuration // They don't change that often.
        FileCacheDuration    = 8 * DefaultCacheDuration // These change even less often.
 
+       // Used when the UDP API Anime query fails, but the HTTP API query succeeds.
+       AnimeIncompleteCacheDuration = 24 * time.Hour
+
        // Used when there's some data missing on a file.
        // Usually happens because the AVDump data hasn't been merged with the database
        // yet, which is done on a daily cron job.