]> git.lizzy.rs Git - go-anidb.git/commitdiff
anidb: Make ReAuth try to use the cache before sending USER query
authorDiogo Franco (Kovensky) <diogomfranco@gmail.com>
Fri, 26 Jul 2013 05:16:28 +0000 (02:16 -0300)
committerDiogo Franco (Kovensky) <diogomfranco@gmail.com>
Fri, 26 Jul 2013 05:16:28 +0000 (02:16 -0300)
auth.go

diff --git a/auth.go b/auth.go
index 6e4af5a83f4917c97d71854f0d21b2aeb5a2fbba..069a095fdca4865aed3a7f4e8599045a296ce83f 100644 (file)
--- a/auth.go
+++ b/auth.go
@@ -117,18 +117,22 @@ func (udp *udpWrap) ReAuth() udpapi.APIReply {
                udp.connected = err == nil
 
                if udp.connected {
-                       // We can't use SendRecv here as it would deadlock
-                       ch := make(chan udpapi.APIReply, 1)
-                       udp.sendQueueCh <- paramSet{
-                               cmd:    "USER",
-                               params: paramMap{"user": decrypt(c.username)},
-                               ch:     ch,
-                       }
-                       reply := <-ch
-
-                       if reply != nil {
-                               uid, _ := parseUserReply(reply)
-                               udp.user = uid.User()
+                       if user := UserByName(decrypt(c.username)); user != nil {
+                               udp.user = user
+                       } else {
+                               // We can't use SendRecv here as it would deadlock
+                               ch := make(chan udpapi.APIReply, 1)
+                               udp.sendQueueCh <- paramSet{
+                                       cmd:    "USER",
+                                       params: paramMap{"user": decrypt(c.username)},
+                                       ch:     ch,
+                               }
+                               reply := <-ch
+
+                               if reply != nil {
+                                       uid, _ := parseUserReply(reply)
+                                       udp.user = uid.User()
+                               }
                        }
                }