diff --git a/cache/postgres.go b/cache/postgres.go index 77166af0dff..0b04514dad6 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,14 +137,15 @@ 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) } 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 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 @@ -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) } 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 }