perf(webui): refactor dashboard modules and optimize API performance

This commit is contained in:
Wha1eChai
2026-01-09 17:58:09 +08:00
parent e909ea6fe3
commit a914821d49
20 changed files with 1420 additions and 599 deletions

View File

@@ -166,10 +166,24 @@ function setupRoutes(app) {
});
}
/**
* Get usage history data
* @returns {object} History data sorted by timestamp
*/
function getHistory() {
const sortedKeys = Object.keys(history).sort();
const sortedData = {};
sortedKeys.forEach(key => {
sortedData[key] = history[key];
});
return sortedData;
}
export default {
setupMiddleware,
setupRoutes,
track,
getFamily,
getShortName
getShortName,
getHistory
};

View File

@@ -249,6 +249,7 @@ app.get('/account-limits', async (req, res) => {
await ensureInitialized();
const allAccounts = accountManager.getAllAccounts();
const format = req.query.format || 'json';
const includeHistory = req.query.includeHistory === 'true';
// Fetch quotas for each account in parallel
const results = await Promise.allSettled(
@@ -429,8 +430,8 @@ app.get('/account-limits', async (req, res) => {
accountStatus.accounts.map(a => [a.email, a])
);
// Default: JSON format
res.json({
// Build response data
const responseData = {
timestamp: new Date().toLocaleString(),
totalAccounts: allAccounts.length,
models: sortedModels,
@@ -468,7 +469,14 @@ app.get('/account-limits', async (req, res) => {
)
};
})
});
};
// Optionally include usage history (for dashboard performance optimization)
if (includeHistory) {
responseData.history = usageStats.getHistory();
}
res.json(responseData);
} catch (error) {
res.status(500).json({
status: 'error',