mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-23 04:42:08 +08:00
refactor(frontend): consolidate query state ownership
Consolidate ordinary query snapshots on SWR and make Profiles own its query key, cache mutation, and invalidation policy. Impact: - remove the generic synchronous query Map while keeping dedicated Mihomo WebSocket snapshots - eliminate duplicate Profiles refreshes while preserving retries and the 800 ms event throttle - preserve preload-backed Verge updates and system proxy rollback behavior - scope uptime polling to the Home Clash info card instead of the app lifetime - leave RunState, Connections, Traffic, backend, and IPC contracts unchanged - reduce frontend code by 72 net lines without adding dependencies
This commit is contained in:
@@ -5,11 +5,11 @@ import { useTranslation } from 'react-i18next'
|
||||
|
||||
import { useClash } from '@/hooks/use-clash'
|
||||
import { useDisplayedMixedPort } from '@/hooks/use-displayed-mixed-port'
|
||||
import { useAppUptime } from '@/hooks/use-system-state'
|
||||
import {
|
||||
useClashConfigData,
|
||||
useRulesData,
|
||||
useSystemData,
|
||||
useUptimeData,
|
||||
} from '@/providers/app-data-context'
|
||||
|
||||
import { EnhancedCard } from './enhanced-card'
|
||||
@@ -28,7 +28,7 @@ export const ClashInfoCard = () => {
|
||||
const { clashConfig } = useClashConfigData()
|
||||
const displayedMixedPort = useDisplayedMixedPort()
|
||||
const { rules } = useRulesData()
|
||||
const { uptime } = useUptimeData()
|
||||
const uptime = useAppUptime()
|
||||
const { systemProxyAddress } = useSystemData()
|
||||
|
||||
// 使用useMemo缓存格式化后的uptime,避免频繁计算
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
type RunState,
|
||||
} from '@/services/cmds'
|
||||
import { showNotice } from '@/services/notice-service'
|
||||
import { setCacheDataAsync, useQuery } from '@/services/query-client'
|
||||
import { setCacheData, useQuery } from '@/services/query-client'
|
||||
|
||||
export const ServiceMigrationDialog = () => {
|
||||
const { t } = useTranslation()
|
||||
@@ -50,7 +50,7 @@ export const ServiceMigrationDialog = () => {
|
||||
const refreshRunState = async () => {
|
||||
try {
|
||||
const data = await getRuntimeState()
|
||||
await setCacheDataAsync<RunState>(runStateQueryKey, data)
|
||||
await setCacheData<RunState>(runStateQueryKey, data)
|
||||
setStateRefreshFailed(false)
|
||||
return data
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user