mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-11 03:38:38 +00:00
(UI) Fix Usage Tab - Don't make expensive UI queries after SpendLogs crosses 1M Rows (#7229)
* ui - fix viewing usage tab when 1M rows * fix don't fetch tagSpend data if DISABLE_EXPENSIVE_DB_QUERIES is True
This commit is contained in:
parent
64e363b3d3
commit
68af5fac59
1 changed files with 44 additions and 32 deletions
|
|
@ -197,21 +197,18 @@ const UsagePage: React.FC<UsagePageProps> = ({
|
|||
return formatter.format(number);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const fetchProxySettings = async () => {
|
||||
if (accessToken) {
|
||||
try {
|
||||
const proxy_settings: ProxySettings = await getProxyUISettings(accessToken);
|
||||
console.log("usage tab: proxy_settings", proxy_settings);
|
||||
setProxySettings(proxy_settings);
|
||||
} catch (error) {
|
||||
console.error("Error fetching proxy settings:", error);
|
||||
}
|
||||
}
|
||||
};
|
||||
fetchProxySettings();
|
||||
}, [accessToken]);
|
||||
|
||||
const fetchProxySettings = async () => {
|
||||
if (accessToken) {
|
||||
try {
|
||||
const proxy_settings: ProxySettings = await getProxyUISettings(accessToken);
|
||||
console.log("usage tab: proxy_settings", proxy_settings);
|
||||
return proxy_settings;
|
||||
} catch (error) {
|
||||
console.error("Error fetching proxy settings:", error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
updateTagSpendData(dateValue.from, dateValue.to);
|
||||
|
|
@ -247,6 +244,10 @@ const UsagePage: React.FC<UsagePageProps> = ({
|
|||
return;
|
||||
}
|
||||
|
||||
if (proxySettings?.DISABLE_EXPENSIVE_DB_QUERIES) {
|
||||
return; // Don't run expensive DB queries - return out when SpendLogs has more than 1M rows
|
||||
}
|
||||
|
||||
// the endTime put it to the last hour of the selected date
|
||||
endTime.setHours(23, 59, 59, 999);
|
||||
|
||||
|
|
@ -404,26 +405,37 @@ const UsagePage: React.FC<UsagePageProps> = ({
|
|||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (accessToken && token && userRole && userID) {
|
||||
if (proxySettings?.DISABLE_EXPENSIVE_DB_QUERIES) {
|
||||
return; // Don't run expensive queries
|
||||
const initlizeUsageData = async () => {
|
||||
if (accessToken && token && userRole && userID) {
|
||||
const proxy_settings: ProxySettings | undefined = await fetchProxySettings();
|
||||
if (proxy_settings) {
|
||||
setProxySettings(proxy_settings); // saved in state so it can be used when rendering UI
|
||||
if (proxy_settings?.DISABLE_EXPENSIVE_DB_QUERIES) {
|
||||
return; // Don't run expensive UI queries - return out of initlizeUsageData at this point
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
console.log("fetching data - valiue of proxySettings", proxySettings);
|
||||
|
||||
|
||||
fetchOverallSpend();
|
||||
fetchProviderSpend();
|
||||
fetchTopKeys();
|
||||
fetchTopModels();
|
||||
fetchGlobalActivity();
|
||||
fetchGlobalActivityPerModel();
|
||||
|
||||
if (isAdminOrAdminViewer(userRole)) {
|
||||
fetchTeamSpend();
|
||||
fetchTagNames();
|
||||
fetchTopTags();
|
||||
fetchTopEndUsers();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
fetchOverallSpend();
|
||||
fetchProviderSpend();
|
||||
fetchTopKeys();
|
||||
fetchTopModels();
|
||||
fetchGlobalActivity();
|
||||
fetchGlobalActivityPerModel();
|
||||
|
||||
if (isAdminOrAdminViewer(userRole)) {
|
||||
fetchTeamSpend();
|
||||
fetchTagNames();
|
||||
fetchTopTags();
|
||||
fetchTopEndUsers();
|
||||
}
|
||||
}
|
||||
initlizeUsageData();
|
||||
}, [accessToken, token, userRole, userID, startTime, endTime]);
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue