diff --git a/models/user_business_analysis.go b/models/user_business_analysis.go index 333867fb2..4cd3539d7 100644 --- a/models/user_business_analysis.go +++ b/models/user_business_analysis.go @@ -719,12 +719,11 @@ func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageS userIndexMap := make(map[int64]float64, 0) maxUserIndex := 0.0 minUserIndex := 100000000.0 - dateRecordBatch := make([]UserBusinessAnalysisAll, 0) for { sess.Select("`user`.*").Table("user").Where(cond).OrderBy("id asc").Limit(PAGE_SIZE, int(indexTotal)) userList := make([]*User, 0) sess.Find(&userList) - + dateRecordBatch := make([]UserBusinessAnalysisAll, 0) for _, userRecord := range userList { var dateRecordAll UserBusinessAnalysisAll dateRecordAll.ID = userRecord.ID @@ -789,7 +788,7 @@ func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageS dateRecordBatch = append(dateRecordBatch, dateRecordAll) if len(dateRecordBatch) >= BATCH_INSERT_SIZE { - insertTable(dateRecordBatch, tableName, statictisSess) + err := insertTable(dateRecordBatch, tableName, statictisSess) insertCount += BATCH_INSERT_SIZE if err != nil { log.Info("insert all data failed." + err.Error()) @@ -804,18 +803,19 @@ func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageS } } } + if len(dateRecordBatch) > 0 { + err := insertTable(dateRecordBatch, tableName, statictisSess) + insertCount += len(dateRecordBatch) + if err != nil { + log.Info("insert all data failed." + err.Error()) + } + } indexTotal += PAGE_SIZE if indexTotal >= count { break } } - if len(dateRecordBatch) > 0 { - insertTable(dateRecordBatch, tableName, statictisSess) - insertCount += len(dateRecordBatch) - if err != nil { - log.Info("insert all data failed." + err.Error()) - } - } + if tableName == "user_business_analysis_all" { log.Info("TotalHasActivityUser=" + fmt.Sprint(userMetrics["TotalHasActivityUser"])) } @@ -835,7 +835,7 @@ func updateUserIndex(tableName string, statictisSess *xorm.Session, userId int64 statictisSess.Exec(updateSql) } -func insertTable(dateRecords []UserBusinessAnalysisAll, tableName string, statictisSess *xorm.Session) { +func insertTable(dateRecords []UserBusinessAnalysisAll, tableName string, statictisSess *xorm.Session) error { insertBatchSql := "INSERT INTO public." + tableName + "(id, count_date, code_merge_count, commit_count, issue_count, comment_count, focus_repo_count, star_repo_count, watched_count, gitea_age_month, commit_code_size, commit_dataset_size, " + @@ -854,7 +854,8 @@ func insertTable(dateRecords []UserBusinessAnalysisAll, tableName string, static } } - statictisSess.Exec(insertBatchSql) + _, err := statictisSess.Exec(insertBatchSql) + return err } func RefreshUserStaticAllTabel(wikiCountMap map[string]int, userMetrics map[string]int) { @@ -2057,7 +2058,9 @@ func queryCloudBrainTask(start_unix int64, end_unix int64) (map[int64]int, map[s } else { resultMap[cloudTaskRecord.UserID] += 1 } - setMapKey("CloudBrainRunTime", cloudTaskRecord.UserID, int(cloudTaskRecord.Duration), resultItemMap) + if cloudTaskRecord.Duration < 100000000 && cloudTaskRecord.Duration > 0 { + setMapKey("CloudBrainRunTime", cloudTaskRecord.UserID, int(cloudTaskRecord.Duration), resultItemMap) + } if cloudTaskRecord.Type == 1 { //npu if cloudTaskRecord.JobType == "TRAIN" { setMapKey("NpuTrainJob", cloudTaskRecord.UserID, 1, resultItemMap)