mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-20 05:42:19 +03:00
getPricingForModel() called the uncached getPricing() on every invocation instead of the existing getCachedPricing() helper (30s TTL, readCache.ts), so usageStats.getUsageStats() re-ran a 3-SELECT + JSON.parse + merge cycle against key_value once per GROUP BY row -- up to 531 times on a large usage_history table -- blocking the event loop for several seconds on /api/usage/history. Every known pricing writer (updatePricing, LiteLLM/models.dev sync) already invalidates this cache via touchPricing()/invalidateDbCache, so a write remains immediately visible; added a regression test that proves both the cache hit path and the invalidation path.
This commit is contained in:
committed by
GitHub
parent
e94752fa53
commit
a96c8381f7
@@ -4,7 +4,7 @@
|
||||
|
||||
import { getDbInstance } from "../core";
|
||||
import { backupDbFile } from "../backup";
|
||||
import { invalidateDbCache } from "../readCache";
|
||||
import { getCachedPricing, invalidateDbCache } from "../readCache";
|
||||
import { PROVIDER_ID_TO_ALIAS } from "@omniroute/open-sse/config/providerModels.ts";
|
||||
import { type JsonRecord, toRecord } from "./shared";
|
||||
|
||||
@@ -131,7 +131,7 @@ export async function getPricingWithSources(): Promise<{
|
||||
}
|
||||
|
||||
export async function getPricingForModel(provider: string, model: string) {
|
||||
const pricing = await getPricing();
|
||||
const pricing = (await getCachedPricing()) as PricingByProvider;
|
||||
|
||||
const findKeyInsensitive = <T>(
|
||||
obj: Record<string, T> | undefined | null,
|
||||
|
||||
Reference in New Issue
Block a user