fix: First 改 Find 消除 record not found 日志噪音
- GetDailyEnergizeExp 用 Find + Limit(1) 替代 First,空结果不触发 GORM ErrRecordNotFound - 移除不再需要的 errors 导入 - 数据库检查确认三张表均存在,daily_exp_summaries 为空属正常状态
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"metazone.cc/metalab/internal/model"
|
||||
@ -83,15 +82,15 @@ func (r *EnergyRepo) CreateEnergizeLog(log *model.PostEnergizeLog) error {
|
||||
// GetDailyEnergizeExp 获取用户当日通过赋能获得的经验值
|
||||
// 无记录时返回 nil, nil(调用方当作 exp=0 处理)
|
||||
func (r *EnergyRepo) GetDailyEnergizeExp(userID uint, date time.Time) (*model.DailyExpSummary, error) {
|
||||
var s model.DailyExpSummary
|
||||
err := r.db.Where("user_id = ? AND date = ?", userID, date).First(&s).Error
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, nil
|
||||
}
|
||||
var summaries []model.DailyExpSummary
|
||||
err := r.db.Where("user_id = ? AND date = ?", userID, date).Limit(1).Find(&summaries).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &s, nil
|
||||
if len(summaries) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return &summaries[0], nil
|
||||
}
|
||||
|
||||
// UpsertDailyExp 创建或更新每日经验汇总
|
||||
|
||||
Reference in New Issue
Block a user