improvement(performance): added revalidation caches on ollama and openrouter models (#1872)

* improvement(performance): added revalidation caches on ollama and openrouter models

* ack PR comments
This commit is contained in:
Waleed
2025-11-10 12:19:22 -08:00
committed by GitHub
parent b03f9702d2
commit 81a12e721e
3 changed files with 6 additions and 5 deletions

View File

@@ -6,8 +6,6 @@ import type { ModelsObject } from '@/providers/ollama/types'
const logger = createLogger('OllamaModelsAPI')
const OLLAMA_HOST = env.OLLAMA_URL || 'http://localhost:11434'
export const dynamic = 'force-dynamic'
/**
* Get available Ollama models
*/
@@ -21,6 +19,7 @@ export async function GET(request: NextRequest) {
headers: {
'Content-Type': 'application/json',
},
next: { revalidate: 60 },
})
if (!response.ok) {

View File

@@ -4,8 +4,6 @@ import { filterBlacklistedModels } from '@/providers/utils'
const logger = createLogger('OpenRouterModelsAPI')
export const dynamic = 'force-dynamic'
interface OpenRouterModel {
id: string
}
@@ -18,7 +16,7 @@ export async function GET(_request: NextRequest) {
try {
const response = await fetch('https://openrouter.ai/api/v1/models', {
headers: { 'Content-Type': 'application/json' },
cache: 'no-store',
next: { revalidate: 300 },
})
if (!response.ok) {

View File

@@ -81,6 +81,10 @@ export const useProvidersStore = create<ProvidersStore>((set, get) => ({
logger.info(`${provider} model fetch already in progress`)
return
}
if (currentState.models.length > 0) {
logger.info(`Skipping ${provider} model fetch - models already loaded`)
return
}
logger.info(`Fetching ${provider} models from API`)