Skip to content

Commit

Permalink
multi: remove fetchAccountHashData.
Browse files Browse the repository at this point in the history
This removes the unused fetchAccountHashData
inerface requirement, associated database
implementations and tests. It has been removed
 because it can be derived from listHashData's results.
  • Loading branch information
dnldd committed Dec 10, 2020
1 parent 258021d commit 409410e
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 63 deletions.
11 changes: 6 additions & 5 deletions gui/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,12 @@ func (c *Cache) updateHashData(hashData map[string][]*pool.HashData) {
for _, entry := range data {
hash, _ := new(big.Rat).SetString(entry.HashRate)
poolHashRate = poolHashRate.Add(poolHashRate, hash)
clientInfo[entry.AccountID] = append(clientInfo[entry.AccountID], &client{
Miner: entry.Miner,
IP: entry.IP,
HashRate: hashString(hash),
})
clientInfo[entry.AccountID] = append(clientInfo[entry.AccountID],
&client{
Miner: entry.Miner,
IP: entry.IP,
HashRate: hashString(hash),
})
}
}

Expand Down
1 change: 0 additions & 1 deletion pool/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ type Database interface {
persistHashData(hashData *HashData) error
updateHashData(hashData *HashData) error
fetchHashData(id string) (*HashData, error)
fetchAccountHashData(id string, minNano int64) ([]*HashData, error)
listHashData(minNano int64) (map[string][]*HashData, error)
pruneHashData(minNano int64) error
}
Expand Down
34 changes: 2 additions & 32 deletions pool/hashdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,38 +65,8 @@ func testHashData(t *testing.T) {
"non-existent hash data, got %v", err)
}

// Ensure fetching account hash data adheres to the minimum update
// time constraint.
fiveMinutesAfter := now.Add(time.Minute * 5).UnixNano()
data, err := db.fetchAccountHashData(xID, fiveMinutesAfter)
if err != nil {
t.Fatal(err)
}

if len(data) > 0 {
t.Fatalf("expected no hash data, got %d", len(data))
}

fiveMinutesBefore := now.Add(-time.Minute * 5).UnixNano()
data, err = db.fetchAccountHashData(xID, fiveMinutesBefore)
if err != nil {
t.Fatal(err)
}

if len(data) != 1 {
t.Fatalf("expected one hash data, got %d", len(data))
}

// Ensure fetching account hash data returns an empty result
// set for a non-existent account.
data, err = db.fetchAccountHashData(yID, fiveMinutesBefore)
if err != nil {
t.Fatal(err)
}

if len(data) > 0 {
t.Fatalf("expected no hash data, got %d", len(data))
}

// Ensure listing account hash data adheres to the minimum update
// time constraint.
Expand All @@ -106,7 +76,7 @@ func testHashData(t *testing.T) {
}

if len(dataset) > 0 {
t.Fatalf("expected no hash data, got %d", len(data))
t.Fatalf("expected no hash data, got %d", len(dataset))
}

dataset, err = db.listHashData(fiveMinutesBefore)
Expand All @@ -115,7 +85,7 @@ func testHashData(t *testing.T) {
}

if len(dataset) != 1 {
t.Fatalf("expected one hash data, got %d", len(data))
t.Fatalf("expected one hash data, got %d", len(dataset))
}

newUpdatedOn := hashData.UpdatedOn + 100
Expand Down
14 changes: 0 additions & 14 deletions pool/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -1056,20 +1056,6 @@ func (db *PostgresDB) fetchHashData(id string) (*HashData, error) {
return &HashData{uuid, accountID, miner, ip, hashRate, updatedOn}, nil
}

// fetchAccountHashData fetches all hash data associated with the provided
// account id.
func (db *PostgresDB) fetchAccountHashData(id string, minNano int64) ([]*HashData, error) {
const funcName = "fetchAccountHashData"
rows, err := db.DB.Query(selectAccountHashData, id, minNano)
if err != nil {
desc := fmt.Sprintf("%s: unable to fetch account hash data: %v",
funcName, err)
return nil, errs.DBError(errs.FetchEntry, desc)
}

return decodeHashDataRows(rows)
}

// listHashData fetches all hash data updated before the provided minimum time
// provided.
func (db *PostgresDB) listHashData(minNano int64) (map[string][]*HashData, error) {
Expand Down
11 changes: 0 additions & 11 deletions pool/sql_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,17 +400,6 @@ const (
FROM hashdata
WHERE uuid=$1;`

selectAccountHashData = `SELECT
uuid,
accountid,
miner,
ip,
hashrate,
updatedon
FROM hashdata
WHERE accountid=$1
AND updatedon > $2;`

listHashData = `SELECT
uuid,
accountid,
Expand Down

0 comments on commit 409410e

Please sign in to comment.