mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-06-16 13:34:04 +08:00
fix(failover): improve cache cleanup for provider health and circuit breaker
- Use removeQueries instead of invalidateQueries when stopping proxy to completely clear health and circuit breaker caches - Clear provider health and circuit breaker caches when removing from failover queue - Refresh failover queue after drag-sort since queue order depends on sort_index - Only show health badge when provider is in failover queue
This commit is contained in:
@@ -183,7 +183,8 @@ export function ProviderCard({
|
||||
? "hover:border-emerald-500/50"
|
||||
: "hover:border-border-active",
|
||||
// 当前激活的供应商边框样式
|
||||
shouldUseGreen && "border-emerald-500/60 shadow-sm shadow-emerald-500/10",
|
||||
shouldUseGreen &&
|
||||
"border-emerald-500/60 shadow-sm shadow-emerald-500/10",
|
||||
shouldUseBlue && "border-blue-500/60 shadow-sm shadow-blue-500/10",
|
||||
!isActiveProvider && "hover:shadow-sm",
|
||||
dragHandleProps?.isDragging &&
|
||||
@@ -233,7 +234,7 @@ export function ProviderCard({
|
||||
</h3>
|
||||
|
||||
{/* 健康状态徽章 */}
|
||||
{isProxyRunning && health && (
|
||||
{isProxyRunning && isInFailoverQueue && health && (
|
||||
<ProviderHealthBadge
|
||||
consecutiveFailures={health.consecutive_failures}
|
||||
/>
|
||||
|
||||
@@ -75,6 +75,11 @@ export function useDragSort(providers: Record<string, Provider>, appId: AppId) {
|
||||
queryKey: ["providers", appId],
|
||||
});
|
||||
|
||||
// 刷新故障转移队列(因为队列顺序依赖 sort_index)
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: ["failoverQueue", appId],
|
||||
});
|
||||
|
||||
// 更新托盘菜单以反映新的排序(失败不影响主操作)
|
||||
try {
|
||||
await providersApi.updateTrayMenu();
|
||||
|
||||
@@ -73,8 +73,10 @@ export function useProxyStatus() {
|
||||
);
|
||||
queryClient.invalidateQueries({ queryKey: ["proxyStatus"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["proxyTakeoverStatus"] });
|
||||
// 清除所有供应商健康状态缓存(后端已清空数据库记录)
|
||||
queryClient.invalidateQueries({ queryKey: ["providerHealth"] });
|
||||
// 彻底删除所有供应商健康状态缓存(后端已清空数据库记录)
|
||||
queryClient.removeQueries({ queryKey: ["providerHealth"] });
|
||||
// 彻底删除所有熔断器统计缓存(代理停止后熔断器状态已重置)
|
||||
queryClient.removeQueries({ queryKey: ["circuitBreakerStats"] });
|
||||
// 注意:故障转移队列和开关状态会保留,不需要刷新
|
||||
},
|
||||
onError: (error: Error) => {
|
||||
|
||||
@@ -162,6 +162,18 @@ export function useRemoveFromFailoverQueue() {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["providers", variables.appType],
|
||||
});
|
||||
// 清除该供应商的健康状态缓存(退出队列后不再需要健康监控)
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["providerHealth", variables.providerId, variables.appType],
|
||||
});
|
||||
// 清除该供应商的熔断器统计缓存
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: [
|
||||
"circuitBreakerStats",
|
||||
variables.providerId,
|
||||
variables.appType,
|
||||
],
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user