refactor: 将上游模型缓存从前端迁移到后端 Redis

- 后端:定时任务刷新时将上游模型写入 Redis 缓存
- 后端:provider_query 优先从缓存读取,支持 force_refresh 参数
- 后端:auto_fetch_models 开启时改为同步获取,确保前端能立即看到数据
- 前端:移除本地缓存,只保留并发请求去重逻辑
- 前端:KeyAllowedModelsEditDialog 添加刷新上游模型按钮
This commit is contained in:
fawney19
2026-01-16 19:10:59 +08:00
parent b2d08f964d
commit 019e148ddb
7 changed files with 148 additions and 112 deletions
@@ -40,10 +40,23 @@
>
已选 {{ selectedModels.length }} 个
</span>
<Loader2
v-if="fetchingUpstreamModels"
class="w-4 h-4 animate-spin text-muted-foreground shrink-0"
/>
<!-- 刷新上游模型按钮 -->
<button
type="button"
class="h-6 w-6 flex items-center justify-center rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors shrink-0"
:disabled="fetchingUpstreamModels"
title="刷新上游模型"
@click="refreshUpstreamModels"
>
<RefreshCw
v-if="!fetchingUpstreamModels"
class="w-3.5 h-3.5"
/>
<Loader2
v-else
class="w-3.5 h-3.5 animate-spin"
/>
</button>
</div>
<!-- 分组列表 -->
@@ -318,7 +331,8 @@ import {
Check,
ChevronDown,
Lock,
LockOpen
LockOpen,
RefreshCw
} from 'lucide-vue-next'
import { Dialog, Button, Input } from '@/components/ui'
import { useToast } from '@/composables/useToast'
@@ -627,11 +641,11 @@ async function loadGlobalModels() {
}
// 从提供商获取模型(使用缓存)
async function fetchUpstreamModels() {
async function fetchUpstreamModels(forceRefresh = false) {
if (!props.providerId || !props.apiKey) return
try {
fetchingUpstreamModels.value = true
const result = await fetchCachedModels(props.providerId, props.apiKey.id)
const result = await fetchCachedModels(props.providerId, props.apiKey.id, forceRefresh)
if (loadingCancelled) return
if (result.models.length > 0) {
upstreamModels.value = result.models
@@ -647,6 +661,14 @@ async function fetchUpstreamModels() {
}
}
// 手动刷新上游模型(强制跳过缓存)
async function refreshUpstreamModels() {
await fetchUpstreamModels(true)
if (upstreamModels.value.length > 0) {
success('上游模型已刷新')
}
}
// 解析 allowed_models
function parseAllowedModels(allowed: AllowedModels): string[] {
if (allowed === null || allowed === undefined) {