(logType int, startTimestamp int64, endTimestamp int64, modelName string, username string, tokenName string, startIdx int, num int, channel int, group string, requestId string, upstreamRequestId string)
| 440 | } |
| 441 | |
| 442 | func GetAllLogs(logType int, startTimestamp int64, endTimestamp int64, modelName string, username string, tokenName string, startIdx int, num int, channel int, group string, requestId string, upstreamRequestId string) (logs []*Log, total int64, err error) { |
| 443 | var tx *gorm.DB |
| 444 | if logType == LogTypeUnknown { |
| 445 | tx = LOG_DB |
| 446 | } else { |
| 447 | tx = LOG_DB.Where("logs.type = ?", logType) |
| 448 | } |
| 449 | |
| 450 | if tx, err = applyExplicitLogTextFilter(tx, "logs.model_name", modelName); err != nil { |
| 451 | return nil, 0, err |
| 452 | } |
| 453 | if tx, err = applyExplicitLogTextFilter(tx, "logs.username", username); err != nil { |
| 454 | return nil, 0, err |
| 455 | } |
| 456 | if tokenName != "" { |
| 457 | tx = tx.Where("logs.token_name = ?", tokenName) |
| 458 | } |
| 459 | if requestId != "" { |
| 460 | tx = tx.Where("logs.request_id = ?", requestId) |
| 461 | } |
| 462 | if upstreamRequestId != "" { |
| 463 | tx = tx.Where("logs.upstream_request_id = ?", upstreamRequestId) |
| 464 | } |
| 465 | if startTimestamp != 0 { |
| 466 | tx = tx.Where("logs.created_at >= ?", startTimestamp) |
| 467 | } |
| 468 | if endTimestamp != 0 { |
| 469 | tx = tx.Where("logs.created_at <= ?", endTimestamp) |
| 470 | } |
| 471 | if channel != 0 { |
| 472 | tx = tx.Where("logs.channel_id = ?", channel) |
| 473 | } |
| 474 | if group != "" { |
| 475 | tx = tx.Where("logs."+logGroupCol+" = ?", group) |
| 476 | } |
| 477 | err = tx.Model(&Log{}).Count(&total).Error |
| 478 | if err != nil { |
| 479 | return nil, 0, err |
| 480 | } |
| 481 | order := "logs.created_at desc, logs.id desc" |
| 482 | if common.UsingLogDatabase(common.DatabaseTypeClickHouse) { |
| 483 | order = clickHouseLogOrder("logs.") |
| 484 | } |
| 485 | err = tx.Order(order).Limit(num).Offset(startIdx).Find(&logs).Error |
| 486 | if err != nil { |
| 487 | return nil, 0, err |
| 488 | } |
| 489 | if common.UsingLogDatabase(common.DatabaseTypeClickHouse) { |
| 490 | assignDisplayLogIds(logs, startIdx) |
| 491 | } |
| 492 | |
| 493 | channelIds := types.NewSet[int]() |
| 494 | for _, log := range logs { |
| 495 | if log.ChannelId != 0 { |
| 496 | channelIds.Add(log.ChannelId) |
| 497 | } |
| 498 | } |
| 499 |
no test coverage detected