Skip to content

Commit 81a12e7

Browse files
authored
improvement(performance): added revalidation caches on ollama and openrouter models (#1872)
* improvement(performance): added revalidation caches on ollama and openrouter models * ack PR comments
1 parent b03f970 commit 81a12e7

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

apps/sim/app/api/providers/ollama/models/route.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import type { ModelsObject } from '@/providers/ollama/types'
66
const logger = createLogger('OllamaModelsAPI')
77
const OLLAMA_HOST = env.OLLAMA_URL || 'http://localhost:11434'
88

9-
export const dynamic = 'force-dynamic'
10-
119
/**
1210
* Get available Ollama models
1311
*/
@@ -21,6 +19,7 @@ export async function GET(request: NextRequest) {
2119
headers: {
2220
'Content-Type': 'application/json',
2321
},
22+
next: { revalidate: 60 },
2423
})
2524

2625
if (!response.ok) {

apps/sim/app/api/providers/openrouter/models/route.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import { filterBlacklistedModels } from '@/providers/utils'
44

55
const logger = createLogger('OpenRouterModelsAPI')
66

7-
export const dynamic = 'force-dynamic'
8-
97
interface OpenRouterModel {
108
id: string
119
}
@@ -18,7 +16,7 @@ export async function GET(_request: NextRequest) {
1816
try {
1917
const response = await fetch('https://openrouter.ai/api/v1/models', {
2018
headers: { 'Content-Type': 'application/json' },
21-
cache: 'no-store',
19+
next: { revalidate: 300 },
2220
})
2321

2422
if (!response.ok) {

apps/sim/stores/providers/store.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ export const useProvidersStore = create<ProvidersStore>((set, get) => ({
8181
logger.info(`${provider} model fetch already in progress`)
8282
return
8383
}
84+
if (currentState.models.length > 0) {
85+
logger.info(`Skipping ${provider} model fetch - models already loaded`)
86+
return
87+
}
8488

8589
logger.info(`Fetching ${provider} models from API`)
8690

0 commit comments

Comments
 (0)