优化日志记录,注释掉价格更新和创建相关的日志输出,以减少冗余信息并提高代码可读性。

This commit is contained in:
wood chen 2025-03-22 11:16:56 +08:00
parent 420e65251f
commit cb0b494085
3 changed files with 24 additions and 18 deletions

View File

@ -149,7 +149,7 @@ func FetchAndSavePrices() error {
log.Printf("更新价格记录: %s", modelData.Slug) log.Printf("更新价格记录: %s", modelData.Slug)
processedCount++ processedCount++
} else { } else {
log.Printf("价格无变化,跳过更新: %s", modelData.Slug) // log.Printf("价格无变化,跳过更新: %s", modelData.Slug)
skippedCount++ skippedCount++
} }
} else { } else {
@ -162,7 +162,7 @@ func FetchAndSavePrices() error {
} }
if changed { if changed {
log.Printf("创建新价格记录: %s", modelData.Slug) // log.Printf("创建新价格记录: %s", modelData.Slug)
processedCount++ processedCount++
} else { } else {
log.Printf("价格创建失败: %s", modelData.Slug) log.Printf("价格创建失败: %s", modelData.Slug)

View File

@ -89,7 +89,7 @@ func UpdateOtherPrices() error {
// 检查是否支持的厂商 // 检查是否支持的厂商
channelType, ok := authorToChannelType[author] channelType, ok := authorToChannelType[author]
if !ok { if !ok {
log.Printf("跳过不支持的厂商: %s", author) // log.Printf("跳过不支持的厂商: %s", author)
skippedCount++ skippedCount++
continue continue
} }
@ -123,7 +123,7 @@ func UpdateOtherPrices() error {
// 检查是否已处理过这个模型 // 检查是否已处理过这个模型
if processedModels[uniqueModelKey] { if processedModels[uniqueModelKey] {
log.Printf("跳过已处理的模型: %s (厂商: %s)", modelName, author) // log.Printf("跳过已处理的模型: %s (厂商: %s)", modelName, author)
skippedCount++ skippedCount++
continue continue
} }
@ -195,7 +195,7 @@ func UpdateOtherPrices() error {
log.Printf("更新价格记录: %s (厂商: %s)", modelName, author) log.Printf("更新价格记录: %s (厂商: %s)", modelName, author)
processedCount++ processedCount++
} else { } else {
log.Printf("价格无变化,跳过更新: %s (厂商: %s)", modelName, author) // log.Printf("价格无变化,跳过更新: %s (厂商: %s)", modelName, author)
skippedCount++ skippedCount++
} }
} else { } else {
@ -207,7 +207,7 @@ func UpdateOtherPrices() error {
} }
if pendingCount > 0 { if pendingCount > 0 {
log.Printf("已存在待审核的相同模型记录,跳过创建: %s (厂商: %s)", modelName, author) // log.Printf("已存在待审核的相同模型记录,跳过创建: %s (厂商: %s)", modelName, author)
skippedCount++ skippedCount++
continue continue
} }
@ -221,7 +221,7 @@ func UpdateOtherPrices() error {
} }
if changed { if changed {
log.Printf("创建新价格记录: %s (厂商: %s)", modelName, author) // log.Printf("创建新价格记录: %s (厂商: %s)", modelName, author)
processedCount++ processedCount++
} else { } else {
log.Printf("价格创建失败: %s (厂商: %s)", modelName, author) log.Printf("价格创建失败: %s (厂商: %s)", modelName, author)
@ -267,25 +267,25 @@ func isInBlacklist(modelName string) bool {
modelNameLower := strings.ToLower(modelName) modelNameLower := strings.ToLower(modelName)
// 记录黑名单匹配过程 // 记录黑名单匹配过程
log.Printf("检查模型是否在黑名单中: %s", modelNameLower) // log.Printf("检查模型是否在黑名单中: %s", modelNameLower)
for _, blacklistItem := range blacklist { for _, blacklistItem := range blacklist {
blacklistItemLower := strings.ToLower(blacklistItem) blacklistItemLower := strings.ToLower(blacklistItem)
// 1. 完全匹配 - 模型名称与黑名单项完全相同 // 1. 完全匹配 - 模型名称与黑名单项完全相同
if modelNameLower == blacklistItemLower { if modelNameLower == blacklistItemLower {
log.Printf("模型【%s】完全匹配黑名单项【%s】", modelNameLower, blacklistItemLower) // log.Printf("模型【%s】完全匹配黑名单项【%s】", modelNameLower, blacklistItemLower)
return true return true
} }
// 2. 包含匹配 - 模型名称中包含黑名单项 // 2. 包含匹配 - 模型名称中包含黑名单项
if strings.Contains(modelNameLower, blacklistItemLower) { if strings.Contains(modelNameLower, blacklistItemLower) {
log.Printf("模型【%s】包含黑名单项【%s】", modelNameLower, blacklistItemLower) // log.Printf("模型【%s】包含黑名单项【%s】", modelNameLower, blacklistItemLower)
return true return true
} }
} }
// 记录未匹配的情况 // 记录未匹配的情况
log.Printf("模型【%s】不在黑名单中", modelNameLower) // log.Printf("模型【%s】不在黑名单中", modelNameLower)
return false return false
} }

View File

@ -2,6 +2,7 @@ package siliconflow_api
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io" "io"
"log" "log"
@ -15,6 +16,8 @@ import (
"aimodels-prices/handlers" "aimodels-prices/handlers"
"aimodels-prices/handlers/rates" "aimodels-prices/handlers/rates"
"aimodels-prices/models" "aimodels-prices/models"
"gorm.io/gorm"
) )
// 常量定义 // 常量定义
@ -93,7 +96,6 @@ func UpdateSiliconFlowPrices() error {
// 检查是否已处理过这个模型 // 检查是否已处理过这个模型
if processedModels[modelName] { if processedModels[modelName] {
log.Printf("跳过已处理的模型: %s", modelName)
skippedCount++ skippedCount++
continue continue
} }
@ -161,10 +163,11 @@ func UpdateSiliconFlowPrices() error {
// 检查是否已存在相同模型的价格记录 // 检查是否已存在相同模型的价格记录
var existingPrice models.Price var existingPrice models.Price
// 使用静默查询,不输出"record not found"错误
result := db.Where("model = ? AND channel_type = ?", modelName, SiliconFlowChannelType).First(&existingPrice) result := db.Where("model = ? AND channel_type = ?", modelName, SiliconFlowChannelType).First(&existingPrice)
if result.Error == nil { if result.Error == nil {
// 使用processPrice函数处理更新第三个参数设置为true表示直接审核通过 // 记录存在,执行更新
_, changed, err := handlers.ProcessPrice(price, &existingPrice, true, CreatedBy) _, changed, err := handlers.ProcessPrice(price, &existingPrice, true, CreatedBy)
if err != nil { if err != nil {
log.Printf("更新价格记录失败 %s: %v", modelName, err) log.Printf("更新价格记录失败 %s: %v", modelName, err)
@ -173,13 +176,12 @@ func UpdateSiliconFlowPrices() error {
} }
if changed { if changed {
log.Printf("更新价格记录: %s", modelName)
processedCount++ processedCount++
} else { } else {
log.Printf("价格无变化,跳过更新: %s", modelName)
skippedCount++ skippedCount++
} }
} else { } else if errors.Is(result.Error, gorm.ErrRecordNotFound) {
// 记录不存在,需要创建新记录
// 检查是否存在相同模型名称的待审核记录 // 检查是否存在相同模型名称的待审核记录
var pendingCount int64 var pendingCount int64
if err := db.Model(&models.Price{}).Where("model = ? AND channel_type = ? AND status = 'pending'", if err := db.Model(&models.Price{}).Where("model = ? AND channel_type = ? AND status = 'pending'",
@ -193,7 +195,7 @@ func UpdateSiliconFlowPrices() error {
continue continue
} }
// 使用processPrice函数处理创建第三个参数设置为true表示直接审核通过 // 创建新记录
_, changed, err := handlers.ProcessPrice(price, nil, true, CreatedBy) _, changed, err := handlers.ProcessPrice(price, nil, true, CreatedBy)
if err != nil { if err != nil {
log.Printf("创建价格记录失败 %s: %v", modelName, err) log.Printf("创建价格记录失败 %s: %v", modelName, err)
@ -202,12 +204,16 @@ func UpdateSiliconFlowPrices() error {
} }
if changed { if changed {
log.Printf("创建新价格记录: %s", modelName)
processedCount++ processedCount++
} else { } else {
log.Printf("价格创建失败: %s", modelName) log.Printf("价格创建失败: %s", modelName)
skippedCount++ skippedCount++
} }
} else {
// 其他错误
log.Printf("查询价格记录时发生错误 %s: %v", modelName, result.Error)
skippedCount++
continue
} }
} }