Skip to content

Fix alias display bug.#249

Open
JcobCN wants to merge 12 commits into
Willxup:mainfrom
JcobCN:main
Open

Fix alias display bug.#249
JcobCN wants to merge 12 commits into
Willxup:mainfrom
JcobCN:main

Conversation

@JcobCN

@JcobCN JcobCN commented Jun 24, 2026

Copy link
Copy Markdown

No description provided.

petros-double-test1 and others added 4 commits June 24, 2026 09:16
- Request event log: show model_alias in the model column, fall back to original name
- Model filter dropdown: returns {value, label} pairs, label prefers alias
- Realtime panel Top5: uses model_alias as display label
- Analysis page (pie chart, efficiency scatter, heatmap): replace original model name with alias via loadModelAliasMap() post-processing
- Cost calculation: new lookupPricingByModelOrAlias() falls back to alias when original model name has no price entry
- Window stats (quota window cost): includes model_alias in GROUP BY and pricing lookup
- All backend layers (repo DTO, service DTO, API payload) carry ModelAlias through

Also fixes duplicate ServiceTier field in usageEventProjectionToRecord.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for model aliases across usage events, overview statistics, and analysis panels, updating both backend Go APIs and frontend React components to use a structured ModelFilterOption (with value and label) instead of plain strings. Feedback on these changes suggests utilizing a 'key' field instead of 'value' in frontend-facing DTOs to avoid rendering issues, removing a redundant 'model' variable in usageEventRecordCost, and optimizing the database query in loadModelAliasMap to prevent performance bottlenecks on the hot usage_events table.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

}
body := resp.Body.String()
if body != `{"models":["claude-sonnet","gpt-5"]}` {
if body != `{"models":[{"value":"claude-sonnet","label":"claude-sonnet"},{"value":"gpt-5","label":"gpt-5"}]}` {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In DTOs intended for frontend consumption, maintain unique identifiers in the 'key' field and use a separate 'label' field strictly for display purposes. Overwriting unique keys with display labels can cause rendering issues in frameworks like React and prevent the client from uniquely identifying data sources.

Suggested change
if body != `{"models":[{"value":"claude-sonnet","label":"claude-sonnet"},{"value":"gpt-5","label":"gpt-5"}]}` {
if body != "{\"models\":[{\"key\":\"claude-sonnet\",\"label\":\"claude-sonnet\"},{\"key\":\"gpt-5\",\"label\":\"gpt-5\"}]}" {
References
  1. In DTOs intended for frontend consumption, maintain unique identifiers in the 'key' field and use a separate 'label' field strictly for display purposes. Overwriting unique keys with display labels can cause rendering issues in frameworks like React and prevent the client from uniquely identifying data sources.

Comment on lines +188 to +189
model := strings.TrimSpace(record.Model)
pricing, ok := lookupPricingByModelOrAlias(pricingByModel, model, record.ModelAlias)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The model variable is redundant because lookupPricingByModelOrAlias already trims the model name internally. You can pass record.Model directly to simplify the code.

Suggested change
model := strings.TrimSpace(record.Model)
pricing, ok := lookupPricingByModelOrAlias(pricingByModel, model, record.ModelAlias)
pricing, ok := lookupPricingByModelOrAlias(pricingByModel, record.Model, record.ModelAlias)

Comment on lines +2368 to +2377
subQuery := db.Model(&entities.UsageEvent{}).
Select("MAX(id)").
Where("model_alias IS NOT NULL AND model_alias != ''").
Group("model")
if err := db.Model(&entities.UsageEvent{}).
Select("model, model_alias").
Where("id IN (?)", subQuery).
Find(&rows).Error; err != nil {
return nil
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Querying the hot usage_events transaction log table with a Group By and IN subquery on every request to load the model alias map can cause severe performance bottlenecks as the table grows. Consider caching this mapping in-memory (e.g., with a short TTL or invalidation on new alias creation) or ensuring that an appropriate index exists on (model_alias, model, id) to avoid full table scans.

References
  1. When performing database lookups for specific records, use parameterized queries and ensure the search is supported by an index to optimize performance and protect against injection attacks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants