chore: adjust grom find 1 sql
This commit is contained in:
@@ -118,7 +118,8 @@ func (lc *LogController) GetLogDetail(c *gin.Context) {
|
||||
}
|
||||
|
||||
var log models.TaskLog
|
||||
if err := database.DB.Where("id = ?", id).First(&log).Error; err != nil {
|
||||
res := database.DB.Where("id = ?", id).Limit(1).Find(&log)
|
||||
if res.Error != nil || res.RowsAffected == 0 {
|
||||
utils.NotFound(c, "日志不存在")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -34,7 +34,8 @@ func (lc *LogWSController) StreamLog(c *gin.Context) {
|
||||
|
||||
// 1. 检查数据库中是否已结束
|
||||
var taskLog models.TaskLog
|
||||
if err := database.DB.Where("id = ?", logID).First(&taskLog).Error; err == nil {
|
||||
res := database.DB.Where("id = ?", logID).Limit(1).Find(&taskLog)
|
||||
if res.Error == nil && res.RowsAffected > 0 {
|
||||
if taskLog.Status != "running" {
|
||||
// 已结束,读取库内日志
|
||||
content, err := utils.DecompressFromBase64(string(taskLog.Output))
|
||||
@@ -74,7 +75,8 @@ func (lc *LogWSController) StreamLog(c *gin.Context) {
|
||||
if !ok {
|
||||
// 任务结束,尝试刷新最后一次库内完整内容
|
||||
var finalLog models.TaskLog
|
||||
if err := database.DB.Where("id = ?", logID).First(&finalLog).Error; err == nil {
|
||||
res := database.DB.Where("id = ?", logID).Limit(1).Find(&finalLog)
|
||||
if res.Error == nil && res.RowsAffected > 0 {
|
||||
content, _ := utils.DecompressFromBase64(string(finalLog.Output))
|
||||
if content != "" {
|
||||
conn.WriteMessage(websocket.TextMessage, []byte("\n--- 任务已结束 ---\n"))
|
||||
|
||||
@@ -65,7 +65,8 @@ func (sc *SettingsController) ChangePassword(c *gin.Context) {
|
||||
|
||||
userID := c.GetString("userID")
|
||||
var user *models.User
|
||||
if err := database.DB.Where("id = ?", userID).First(&user).Error; err != nil {
|
||||
res := database.DB.Where("id = ?", userID).Limit(1).Find(&user)
|
||||
if res.Error != nil || res.RowsAffected == 0 {
|
||||
utils.NotFound(c, "用户不存在")
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user