Browse Source

// GetMinerCharts retrieves miner charts from Redis and returns them as []*MinerCharts. // The hashNum parameter determines the maximum number of items to retrieve from the leaderboard. // The login parameter is used as the key to access the leaderboard. // The function also supports optional arguments that can be used to perform deletion operations on the leaderboard. // If the deleteCount argument value is 0, all items in the leaderboard older than 24 hours are removed. // Otherwise, the first deleteCount items are removed from the leaderboard. // The result is a slice of MinerCharts objects representing the retrieved charts. // In case of an error, an error object is returned.

// GetMinerCharts retrieves miner charts from Redis and returns them as []*MinerCharts.
// The hashNum parameter determines the maximum number of items to retrieve from the leaderboard.
// The login parameter is used as the key to access the leaderboard.
// The function also supports optional arguments that can be used to perform deletion operations on the leaderboard.
// If the deleteCount argument value is 0, all items in the leaderboard older than 24 hours are removed.
// Otherwise, the first deleteCount items are removed from the leaderboard.
// The result is a slice of MinerCharts objects representing the retrieved charts.
// In case of an error, an error object is returned.
master
yuriy0803 3 years ago
parent
commit
d2f14c70be
  1. 4
      api/server.go
  2. 16
      storage/redis.go

4
api/server.go

@ -441,6 +441,10 @@ func (s *ApiServer) AccountIndex(w http.ResponseWriter, r *http.Request) {
stats["pageSize"] = s.config.Payments stats["pageSize"] = s.config.Payments
stats["exchangedata"] = generalstats["exchangedata"] stats["exchangedata"] = generalstats["exchangedata"]
stats["minerCharts"], err = s.backend.GetMinerCharts(s.config.MinerChartsNum, login) stats["minerCharts"], err = s.backend.GetMinerCharts(s.config.MinerChartsNum, login)
// Aufruf mit Löschoperation (alle Einträge, die älter als 24 Stunden sind, werden gelöscht)
deleteCount := int64(0)
stats["minerCharts"], err = s.backend.GetMinerCharts(s.config.MinerChartsNum, login, deleteCount)
stats["shareCharts"], err = s.backend.GetShareCharts(s.config.ShareChartsNum, login) stats["shareCharts"], err = s.backend.GetShareCharts(s.config.ShareChartsNum, login)
stats["paymentCharts"], err = s.backend.GetPaymentCharts(login) stats["paymentCharts"], err = s.backend.GetPaymentCharts(login)
reply = &Entry{stats: stats, updatedAt: now} reply = &Entry{stats: stats, updatedAt: now}

16
storage/redis.go

@ -436,20 +436,26 @@ func (r *RedisClient) GetAllMinerAccount() (account []string, err error) {
return account, nil return account, nil
} }
func (r *RedisClient) GetMinerCharts(hashNum int64, login string) (stats []*MinerCharts, err error) { func (r *RedisClient) GetMinerCharts(hashNum int64, login string, args ...int64) (stats []*MinerCharts, err error) {
tx := r.client.Multi() tx := r.client.Multi()
defer tx.Close() defer tx.Close()
now := util.MakeTimestamp() / 1000 now := util.MakeTimestamp() / 1000
cmds, err := tx.Exec(func() error { cmds, err := tx.Exec(func() error {
tx.ZRemRangeByScore(r.formatKey("charts", "miner", login), "-inf", fmt.Sprint("(", now-172800)) if len(args) > 0 && args[0] >= 0 {
tx.ZRevRangeWithScores(r.formatKey("charts", "miner", login), 0, hashNum) deleteCount := args[0]
if deleteCount == 0 {
tx.ZRemRangeByScore(r.formatKey("charts", "miner", login), "-inf", fmt.Sprint("(", now-86400))
} else {
tx.ZRemRangeByRank(r.formatKey("charts", "miner", login), 0, deleteCount-1)
}
}
tx.ZRevRangeWithScores(r.formatKey("charts", "miner", login), 0, hashNum-1)
return nil return nil
}) })
if err != nil { if err != nil {
return nil, err return nil, err
} }
stats = convertMinerChartsResults(cmds[1].(*redis.ZSliceCmd)) stats = convertMinerChartsResults(cmds[len(cmds)-1].(*redis.ZSliceCmd))
return stats, nil return stats, nil
} }

Loading…
Cancel
Save