From 6f8c5a8e9933e8188d16cabb5dc7f95ba3d4852e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Tue, 20 Sep 2022 13:57:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8C=89=E6=97=A5=E5=B8=A6?= =?UTF-8?q?=E5=AE=BD=E5=B3=B0=E5=80=BC=E6=9F=A5=E8=AF=A2=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=9A=84Bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/db/models/server_bandwidth_stat_dao.go | 11 ++++++----- internal/db/models/user_bandwidth_stat_dao.go | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/internal/db/models/server_bandwidth_stat_dao.go b/internal/db/models/server_bandwidth_stat_dao.go index 937e80a9..248c9c6b 100644 --- a/internal/db/models/server_bandwidth_stat_dao.go +++ b/internal/db/models/server_bandwidth_stat_dao.go @@ -85,8 +85,8 @@ func (this *ServerBandwidthStatDAO) UpdateServerBandwidth(tx *dbs.Tx, userId int func (this *ServerBandwidthStatDAO) FindMinutelyPeekBandwidthBytes(tx *dbs.Tx, serverId int64, day string, minute string) (int64, error) { return this.Query(tx). Table(this.partialTable(serverId)). - Result("bytes"). Attr("serverId", serverId). + Result("bytes"). Attr("day", day). Attr("timeAt", minute). FindInt64Col(0) @@ -102,8 +102,8 @@ func (this *ServerBandwidthStatDAO) FindHourlyBandwidthStats(tx *dbs.Tx, serverI ones, _, err := this.Query(tx). Table(this.partialTable(serverId)). - Result("MAX(bytes) AS bytes", "CONCAT(day, '.', SUBSTRING(timeAt, 1, 2)) AS fullTime"). Attr("serverId", serverId). + Result("MAX(bytes) AS bytes", "CONCAT(day, '.', SUBSTRING(timeAt, 1, 2)) AS fullTime"). Gte("CONCAT(day, '.', SUBSTRING(timeAt, 1, 2))", timeutil.FormatTime("Ymd.H", timestamp)). Group("fullTime"). FindOnes() @@ -150,6 +150,7 @@ func (this *ServerBandwidthStatDAO) FindHourlyBandwidthStats(tx *dbs.Tx, serverI func (this *ServerBandwidthStatDAO) FindDailyPeekBandwidthBytes(tx *dbs.Tx, serverId int64, day string) (int64, error) { return this.Query(tx). Table(this.partialTable(serverId)). + Attr("serverId", serverId). Attr("day", day). Result("MAX(bytes)"). FindInt64Col(0) @@ -265,8 +266,8 @@ func (this *ServerBandwidthStatDAO) FindMonthlyPercentile(tx *dbs.Tx, serverId i if percentile >= 100 { result, err = this.Query(tx). Table(this.partialTable(serverId)). - Result("bytes"). Attr("serverId", serverId). + Result("bytes"). Between("day", month+"01", month+"31"). Desc("bytes"). Limit(1). @@ -296,8 +297,8 @@ func (this *ServerBandwidthStatDAO) FindMonthlyPercentile(tx *dbs.Tx, serverId i // 查询 nth 位置 result, err = this.Query(tx). Table(this.partialTable(serverId)). - Result("bytes"). Attr("serverId", serverId). + Result("bytes"). Between("day", month+"01", month+"31"). Desc("bytes"). Offset(offset). @@ -309,7 +310,7 @@ func (this *ServerBandwidthStatDAO) FindMonthlyPercentile(tx *dbs.Tx, serverId i // Clean 清理过期数据 func (this *ServerBandwidthStatDAO) Clean(tx *dbs.Tx) error { - var day = timeutil.Format("Ymd", time.Now().AddDate(0, 0, -62)) // 保留大约2个月的数据 + var day = timeutil.Format("Ymd", time.Now().AddDate(0, 0, -100)) // 保留大约3个月的数据 return this.runBatch(func(table string, locker *sync.Mutex) error { _, err := this.Query(tx). Table(table). diff --git a/internal/db/models/user_bandwidth_stat_dao.go b/internal/db/models/user_bandwidth_stat_dao.go index 17fb0a4a..c342ff98 100644 --- a/internal/db/models/user_bandwidth_stat_dao.go +++ b/internal/db/models/user_bandwidth_stat_dao.go @@ -106,7 +106,7 @@ func (this *UserBandwidthStatDAO) FindUserPeekBandwidthInDay(tx *dbs.Tx, userId // Clean 清理过期数据 func (this *UserBandwidthStatDAO) Clean(tx *dbs.Tx) error { - var day = timeutil.Format("Ymd", time.Now().AddDate(0, 0, -62)) // 保留大约2个月的数据 + var day = timeutil.Format("Ymd", time.Now().AddDate(0, 0, -100)) // 保留大约3个月的数据 return this.runBatch(func(table string, locker *sync.Mutex) error { _, err := this.Query(tx). Table(table).