Align console behavior with operator routing and image workflow expectations

Constraint: Must preserve current exchange-rate logic, same-group routing boundary, and temporary image-file behavior while fixing UX-visible inconsistencies.
Rejected: Large frontend chunk refactor | introduced risky circular chunking and did not improve deliverability for this rollout.
Confidence: medium
Scope-risk: moderate
Directive: Keep channel failover constrained to the selected group and preserve Beijing-day semantics for user cache dashboard metrics.
Tested: go test ./controller ./model ./service ./common -count=1; npm run build; remote smoke on source deployment at http://38.76.218.56:18081/ plus /api/status and /api/image-studio/settings.
Not-tested: Browser-driven end-to-end verification of every console page interaction.
This commit is contained in:
ikmkj
2026-05-05 15:27:51 +08:00
parent 92ee465a41
commit 8ee89478a9
46 changed files with 1341 additions and 289 deletions

View File

@@ -221,11 +221,9 @@ type CacheDashboardMetrics struct {
}
type cacheMetricRow struct {
CreatedAt int64 `gorm:"column:created_at"`
PromptTokens int `gorm:"column:prompt_tokens"`
CompletionTokens int `gorm:"column:completion_tokens"`
ModelName string `gorm:"column:model_name"`
Other string `gorm:"column:other"`
CreatedAt int64 `gorm:"column:created_at"`
PromptTokens int `gorm:"column:prompt_tokens"`
Other string `gorm:"column:other"`
}
type DashboardConsumeStats struct {
@@ -330,14 +328,26 @@ func finalizeCacheMetrics(m *CacheDashboardMetrics) {
}
}
var dashboardMetricsLocation = time.FixedZone("Asia/Shanghai", 8*60*60)
func getDashboardDayStartUnix(now time.Time) int64 {
localNow := now.In(dashboardMetricsLocation)
return time.Date(
localNow.Year(),
localNow.Month(),
localNow.Day(),
0, 0, 0, 0,
dashboardMetricsLocation,
).Unix()
}
func GetUserCacheDashboardMetrics(userId int) (CacheDashboardMetrics, CacheDashboardMetrics, error) {
now := time.Now()
start := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()).Unix()
start := getDashboardDayStartUnix(time.Now())
overall := CacheDashboardMetrics{}
today := CacheDashboardMetrics{}
var rows []cacheMetricRow
err := LOG_DB.Model(&Log{}).
Select("created_at, prompt_tokens, completion_tokens, model_name, other").
Select("created_at, prompt_tokens, other").
Where("user_id = ? AND type = ?", userId, LogTypeConsume).
Order("id ASC").
FindInBatches(&rows, 1000, func(tx *gorm.DB, batch int) error {