From 7bc6618c097ec048cfccb69fcdbbb0cde46e8be6 Mon Sep 17 00:00:00 2001 From: Andrew Sweeney Date: Thu, 4 May 2017 11:20:28 -0400 Subject: [PATCH 1/4] Switch to gob encoding --- cache/postgres.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/cache/postgres.go b/cache/postgres.go index 77166af0dff..f83614e6532 100644 --- a/cache/postgres.go +++ b/cache/postgres.go @@ -3,7 +3,7 @@ package cache import ( "bytes" "database/sql" - "encoding/binary" + "encoding/gob" "fmt" @@ -103,7 +103,8 @@ func (c *PostgresDataCache) GetDomain(key string) (*Domain, error) { b, err := c.lru.Get([]byte(key)) if err == nil { buf := bytes.NewReader(b) - err = binary.Read(buf, binary.BigEndian, &d) + dec := gob.NewDecoder(buf) + err = dec.Decode(&d) if err != nil { panic(err) } @@ -118,8 +119,9 @@ func (c *PostgresDataCache) GetDomain(key string) (*Domain, error) { d.Domain = domain - buf := &bytes.Buffer{} - err = binary.Write(buf, binary.BigEndian, &d) + buf := bytes.Buffer{} + enc := gob.NewEncoder(&buf) + enc.Encode(&d) if err != nil { panic(err) } @@ -135,7 +137,8 @@ func (c *PostgresDataCache) GetAccount(key string) (*Account, error) { b, err := c.lru.Get([]byte(key)) if err == nil { buf := bytes.NewReader(b) - err = binary.Read(buf, binary.BigEndian, &account) + dec := gob.NewDecoder(buf) + err = dec.Decode(&account) if err != nil { panic(err) } @@ -150,8 +153,9 @@ func (c *PostgresDataCache) GetAccount(key string) (*Account, error) { account.ID = id - buf := &bytes.Buffer{} - err = binary.Write(buf, binary.BigEndian, &account) + buf := bytes.Buffer{} + enc := gob.NewEncoder(&buf) + err = enc.Encode(&account) if err != nil { panic(err) } From 8cc76863cd6e5d46e4566fb915395835479ff507 Mon Sep 17 00:00:00 2001 From: Andrew Sweeney Date: Thu, 4 May 2017 11:22:55 -0400 Subject: [PATCH 2/4] hide internal errors --- pbs_light.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pbs_light.go b/pbs_light.go index f1723a35b6e..00bddc67910 100644 --- a/pbs_light.go +++ b/pbs_light.go @@ -169,7 +169,7 @@ func auction(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { _, err = dataCache.GetAccount(pbs_req.AccountID) if err != nil { glog.Info("Invalid account id: ", err) - writeAuctionError(w, "Unknown account id", err) + writeAuctionError(w, "Unknown account id", fmt.Errorf("Unknown account")) mErrorMeter.Mark(1) return } From bb968d755fb9c8f823364be30ca1da25481497e1 Mon Sep 17 00:00:00 2001 From: Andrew Sweeney Date: Thu, 4 May 2017 12:33:21 -0400 Subject: [PATCH 3/4] Fix account search --- cache/postgres.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache/postgres.go b/cache/postgres.go index f83614e6532..83969ec94f4 100644 --- a/cache/postgres.go +++ b/cache/postgres.go @@ -145,7 +145,7 @@ func (c *PostgresDataCache) GetAccount(key string) (*Account, error) { return &account, nil } - err = c.db.QueryRow("SELECT domain FROM domains_domain where domain = $1 LIMIT 1", key).Scan(&id) + err = c.db.QueryRow("SELECT domain FROM accounts_account where uuid = $1 LIMIT 1", key).Scan(&id) if err != nil { /* TODO -- We should store failed attempts in the LRU as well to stop from hitting to DB */ return nil, err From 13584d2688a9ad3239c1c4605f68ffcae1b3d755 Mon Sep 17 00:00:00 2001 From: Andrew Sweeney Date: Thu, 4 May 2017 14:24:58 -0400 Subject: [PATCH 4/4] Fix account query --- cache/postgres.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache/postgres.go b/cache/postgres.go index 83969ec94f4..0b04514dad6 100644 --- a/cache/postgres.go +++ b/cache/postgres.go @@ -145,7 +145,7 @@ func (c *PostgresDataCache) GetAccount(key string) (*Account, error) { return &account, nil } - err = c.db.QueryRow("SELECT domain FROM accounts_account where uuid = $1 LIMIT 1", key).Scan(&id) + err = c.db.QueryRow("SELECT uuid FROM accounts_account where uuid = $1 LIMIT 1", key).Scan(&id) if err != nil { /* TODO -- We should store failed attempts in the LRU as well to stop from hitting to DB */ return nil, err