Skip to content

Commit b93c228

Browse files
committed
perf(opencode): skip redundant missing-pricing check when cost is known
calculate_open_code_cost and missing_open_code_pricing independently iterate through the same model candidates. When the cost calculation already found a valid positive cost (either from a stored cost_usd field or from pricing lookup), skip the missing-pricing check entirely since pricing was already resolved.
1 parent 198abf1 commit b93c228

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

  • rust/crates/ccusage/src/adapter/opencode

‎rust/crates/ccusage/src/adapter/opencode/parser.rs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,14 @@ pub(crate) fn message_value_to_entry(
130130
};
131131
let cost =
132132
calculate_open_code_cost(&model, &provider, cost_usage, data.cost_usd, mode, pricing);
133-
let missing_pricing_model =
134-
missing_open_code_pricing(&model, &provider, cost_usage, data.cost_usd, mode, pricing);
133+
// If we already have a usable positive cost (calculated or stored), skip
134+
// the redundant missing-pricing check — it would iterate through the same
135+
// model candidates and find nothing missing.
136+
let missing_pricing_model = if cost > 0.0 {
137+
None
138+
} else {
139+
missing_open_code_pricing(&model, &provider, cost_usage, data.cost_usd, mode, pricing)
140+
};
135141
let loaded_session_id = data
136142
.session_id
137143
.clone()

0 commit comments

Comments
 (0)