mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-04 09:13:08 +00:00
refactor: improve time constant readability
- Rename FAILURE_COOLDOWN to FAILURE_COOLDOWN_MS with explicit calculation - Add SUCCESS_CACHE_MS constant to replace magic number 300000 - Use multiplication (30 * 1000, 5 * 60 * 1000) to make units explicit Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3115,23 +3115,29 @@ export const useAppStore = create<AppState & AppActions>()((set, get) => ({
|
|||||||
|
|
||||||
// Codex Models actions
|
// Codex Models actions
|
||||||
fetchCodexModels: async (forceRefresh = false) => {
|
fetchCodexModels: async (forceRefresh = false) => {
|
||||||
|
const FAILURE_COOLDOWN_MS = 30 * 1000; // 30 seconds
|
||||||
|
const SUCCESS_CACHE_MS = 5 * 60 * 1000; // 5 minutes
|
||||||
|
|
||||||
const { codexModelsLastFetched, codexModelsLoading, codexModelsLastFailedAt } = get();
|
const { codexModelsLastFetched, codexModelsLoading, codexModelsLastFailedAt } = get();
|
||||||
|
|
||||||
// Skip if already loading
|
// Skip if already loading
|
||||||
if (codexModelsLoading) return;
|
if (codexModelsLoading) return;
|
||||||
|
|
||||||
// Skip if recently failed (< 30 seconds ago) and not forcing refresh
|
// Skip if recently failed and not forcing refresh
|
||||||
const FAILURE_COOLDOWN = 30000; // 30 seconds
|
|
||||||
if (
|
if (
|
||||||
!forceRefresh &&
|
!forceRefresh &&
|
||||||
codexModelsLastFailedAt &&
|
codexModelsLastFailedAt &&
|
||||||
Date.now() - codexModelsLastFailedAt < FAILURE_COOLDOWN
|
Date.now() - codexModelsLastFailedAt < FAILURE_COOLDOWN_MS
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip if recently fetched (< 5 minutes ago) and not forcing refresh
|
// Skip if recently fetched successfully and not forcing refresh
|
||||||
if (!forceRefresh && codexModelsLastFetched && Date.now() - codexModelsLastFetched < 300000) {
|
if (
|
||||||
|
!forceRefresh &&
|
||||||
|
codexModelsLastFetched &&
|
||||||
|
Date.now() - codexModelsLastFetched < SUCCESS_CACHE_MS
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user