]> git.lizzy.rs Git - go-anidb.git/commitdiff
anidb: Avoid crash during MyListAdd / MyListEdit
authorDiogo Franco (Kovensky) <diogomfranco@gmail.com>
Fri, 26 Jul 2013 15:20:43 +0000 (12:20 -0300)
committerDiogo Franco (Kovensky) <diogomfranco@gmail.com>
Fri, 26 Jul 2013 15:20:43 +0000 (12:20 -0300)
Could happen if a file is added without a cached MyListEntry. Make a fake
MyListEntry and cache that, with an old enough Cached timestamp to make
it always stale.

Also change the always stale timestamp in parseMylistReply to a more
reliably ancient one.

mylistcache.go
mylistmanip.go

index ed6a8ecff368dd7abfa642b75d5d5c7332d980e9..0aa837ae8aba96b6f8720834267d477452946fae 100644 (file)
@@ -237,7 +237,7 @@ func (adb *AniDB) parseMylistReply(reply udpapi.APIReply) *MyListEntry {
                                if mla.Cached.IsZero() {
                                        // as attractive as such an ancient mtime would be,
                                        // few filesystems can represent it; just make it old enough
-                                       mla.Cached = now.Add(-2 * MyListCacheDuration)
+                                       mla.Cached = time.Unix(0, 0),
                                }
 
                                Cache.Set(mla, key...)
index f643c5fab5f2ff0bc8065d4f837aa3ed47fc8709..49c027893d814ca80687d96139229b02bfa11fc0 100644 (file)
@@ -86,13 +86,29 @@ func (set *MyListSet) update(uid UID, f *File, lid LID) {
        Cache.Set(mla, "mylist-anime", uid, f.AID)
        Cache.Chtime(mla.Cached, "mylist-anime", uid, f.AID)
 
+       e := lid.MyListEntry()
        if set == nil ||
                (set.ViewDate == nil && set.Watched == nil && set.State == nil &&
                        set.Source == nil && set.Storage == nil && set.Other == nil) {
                return
        }
+       if e == nil {
+               now := time.Now()
+               e = &MyListEntry{
+                       LID: lid,
+
+                       AID: f.AID,
+                       EID: f.EID,
+                       FID: f.FID,
+                       GID: f.GID,
+
+                       DateAdded: now,
+
+                       // make sure it's expired
+                       Cached: time.Unix(0, 0),
+               }
+       }
 
-       e := lid.MyListEntry()
        if set.ViewDate != nil {
                e.DateWatched = *set.ViewDate
        } else if set.Watched != nil {