From d2f14c70be08358632aa0a60f1636df0823d9b83 Mon Sep 17 00:00:00 2001 From: yuriy0803 <68668177+yuriy0803@users.noreply.github.com> Date: Mon, 19 Jun 2023 23:37:14 +0200 Subject: [PATCH] // 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. --- api/server.go | 4 ++++ storage/redis.go | 16 +++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/api/server.go b/api/server.go index 69cf037..34ba30c 100644 --- a/api/server.go +++ b/api/server.go @@ -441,6 +441,10 @@ func (s *ApiServer) AccountIndex(w http.ResponseWriter, r *http.Request) { stats["pageSize"] = s.config.Payments stats["exchangedata"] = generalstats["exchangedata"] 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["paymentCharts"], err = s.backend.GetPaymentCharts(login) reply = &Entry{stats: stats, updatedAt: now} diff --git a/storage/redis.go b/storage/redis.go index 7dd6861..ce2d819 100644 --- a/storage/redis.go +++ b/storage/redis.go @@ -436,20 +436,26 @@ func (r *RedisClient) GetAllMinerAccount() (account []string, err error) { 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() defer tx.Close() now := util.MakeTimestamp() / 1000 cmds, err := tx.Exec(func() error { - tx.ZRemRangeByScore(r.formatKey("charts", "miner", login), "-inf", fmt.Sprint("(", now-172800)) - tx.ZRevRangeWithScores(r.formatKey("charts", "miner", login), 0, hashNum) + if len(args) > 0 && args[0] >= 0 { + 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 }) if err != nil { return nil, err } - stats = convertMinerChartsResults(cmds[1].(*redis.ZSliceCmd)) + stats = convertMinerChartsResults(cmds[len(cmds)-1].(*redis.ZSliceCmd)) return stats, nil }