修改计算规则以及数据库

This commit is contained in:
2025-08-10 02:46:52 +08:00
parent dcd6b42a66
commit d8995bfe36
6 changed files with 733 additions and 102 deletions

View File

@@ -1198,14 +1198,22 @@ export const api = {
/**
* Gets overall usage statistics
* @param days - Optional number of days to look back
* @returns Promise resolving to usage statistics
*/
async getUsageStats(): Promise<UsageStats> {
async getUsageStats(days?: number): Promise<UsageStats> {
try {
return await invoke<UsageStats>("get_usage_stats");
// 使用缓存版本的API它会自动更新缓存
return await invoke<UsageStats>("usage_get_stats_cached", { days });
} catch (error) {
console.error("Failed to get usage stats:", error);
throw error;
console.error("Failed to get cached usage stats, falling back to direct scan:", error);
// 如果缓存版本失败,回退到原版本
try {
return await invoke<UsageStats>("get_usage_stats", { days });
} catch (fallbackError) {
console.error("Fallback to original API also failed:", fallbackError);
throw error;
}
}
},
@@ -1262,6 +1270,19 @@ export const api = {
}
},
/**
* Clears the usage cache and forces recalculation
* @returns Promise resolving to success message
*/
async clearUsageCache(): Promise<string> {
try {
return await invoke<string>("usage_clear_cache");
} catch (error) {
console.error("Failed to clear usage cache:", error);
throw error;
}
},
/**
* Creates a checkpoint for the current session state
*/