From 8484c68f30a94fad5ea2f122edd700a4a25c576c Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Wed, 1 Nov 2023 14:25:36 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/cloudbrain/statistic.go | 76 +++----------------------------- 1 file changed, 5 insertions(+), 71 deletions(-) diff --git a/services/cloudbrain/statistic.go b/services/cloudbrain/statistic.go index b144bde6c6..328d32a5b9 100644 --- a/services/cloudbrain/statistic.go +++ b/services/cloudbrain/statistic.go @@ -1,7 +1,6 @@ package cloudbrain import ( - "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" "time" @@ -20,50 +19,8 @@ func CardStatistic() { } func daysAllStatistic() { - if models.HasTotalTypeXPUInfoStatisticRecord() && !setting.CardStatistic.AllDayRest { - beginTime := models.GetTotalTypeLatestUpdateUnix() - if beginTime == 0 { - daysStatistic(0, models.TypeAllDays) - } else { - statisticMap, err := getStatisticInfoMap(0, models.TypeAllDays, true, beginTime) - if err != nil { - return - } - recordsInDB, err := models.FindTotalTypeXPUInfoStatisticRecords() - if err != nil { - log.Error("can not get xpu statistic records", err) - return - } - - xpuInfos, err := models.GetXPUInfos() - if err != nil { - log.Error("can not get XPU base info", err) - return - } - - var recordsMap = make(map[string]models.XPUInfoStatistic, len(recordsInDB)) - for _, record := range recordsInDB { - for _, xpuInfo := range xpuInfos { - if record.InfoID == xpuInfo.ID { - recordsMap[xpuInfo.CardType] = record - } - } - } - for k, v := range statisticMap { - if record, ok := recordsMap[k]; ok { - v.TaskCount += record.TaskCount - v.UserCount += record.UserCount - v.UsedDuration += record.UsedDuration - } - - } - - updateOrInsertStatisticRecord(statisticMap) - } - } else { - daysStatistic(0, models.TypeAllDays) - } + daysStatistic(0, models.TypeAllDays) } func sevenDayStatistic() { @@ -79,7 +36,7 @@ func thirtyDayStatistic() { } func daysStatistic(days int, statisticType int) { - xpuCardStatisticMap, err := getStatisticInfoMap(days, statisticType, false) + xpuCardStatisticMap, err := getStatisticInfoMap(days, statisticType) if err != nil { return } @@ -98,7 +55,7 @@ func updateOrInsertStatisticRecord(xpuCardStatisticMap map[string]*models.XPUInf } } -func getStatisticInfoMap(days int, statisticType int, lookBefore bool, beginTime ...int64) (map[string]*models.XPUInfoStatistic, error) { +func getStatisticInfoMap(days int, statisticType int, beginTime ...int64) (map[string]*models.XPUInfoStatistic, error) { endTimeUnix := time.Now().Unix() beginTimeUnix := time.Now().AddDate(0, 0, -days).Unix() if days == 0 { @@ -174,31 +131,8 @@ func getStatisticInfoMap(days int, statisticType int, lookBefore bool, beginTime v.UsedDuration += calculateCardDuration(task.Cloudbrain) } if _, found := xpuCardStatisticUserMap[task.Spec.AccCardType][task.UserID]; !found { - if lookBefore { - _, count, err := models.CloudbrainAll(&models.CloudbrainsOptions{ - UserID: task.UserID, - ListOptions: models.ListOptions{ - Page: 1, - PageSize: 1, - }, - NeedRepoInfo: false, - BeginTimeUnix: 1, - EndTimeUnix: beginTimeUnix, - Type: -1, - AccCardsNum: -1, - AccCardType: task.Spec.AccCardType, - }) - if err != nil { - log.Error("Get job failed:", err) - return nil, err - } - if count == 0 { - v.UserCount += 1 - } - - } else { - v.UserCount += 1 - } + + v.UserCount += 1 xpuCardStatisticUserMap[task.Spec.AccCardType][task.UserID] = struct{}{} } } -- 2.34.1 From af71909bf48e2c7476262ec698ee0f0a14e0f55b Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Wed, 1 Nov 2023 14:28:00 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/setting/setting.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 02ffc19f4a..59c55f0c3b 100755 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -663,7 +663,6 @@ var ( Enabled bool Cron string RunAtStart bool - AllDayRest bool }{} C2NetInfos *C2NetSqInfos @@ -1916,8 +1915,7 @@ func getCardStatistic() { sec := Cfg.Section("card_statistic") CardStatistic.Enabled = sec.Key("ENABLED").MustBool(false) CardStatistic.Cron = sec.Key("CRON").MustString("@daily") - CardStatistic.RunAtStart = sec.Key("RUN_AT_START").MustBool(false) - CardStatistic.AllDayRest = sec.Key("ALL_DAY_RESET").MustBool(false) + CardStatistic.RunAtStart = sec.Key("RUN_AT_START").MustBool(false)git } func GetGrampusConfig() { -- 2.34.1 From 07e01c1d58c7ea10877783618ee6115e9a5a992f Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Wed, 1 Nov 2023 14:30:24 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E7=BC=96=E8=AF=91=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/setting/setting.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 59c55f0c3b..b5bc7a1e7e 100755 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -1915,7 +1915,7 @@ func getCardStatistic() { sec := Cfg.Section("card_statistic") CardStatistic.Enabled = sec.Key("ENABLED").MustBool(false) CardStatistic.Cron = sec.Key("CRON").MustString("@daily") - CardStatistic.RunAtStart = sec.Key("RUN_AT_START").MustBool(false)git + CardStatistic.RunAtStart = sec.Key("RUN_AT_START").MustBool(false) } func GetGrampusConfig() { -- 2.34.1