perf: Reduce retry delays and eliminate unnecessary timeouts for improved responsiveness.

This commit is contained in:
kuekhaoyang
2025-11-24 17:46:12 +08:00
parent 82c1f38685
commit 0df6c27178
4 changed files with 6 additions and 8 deletions
+3 -3
View File
@@ -39,8 +39,8 @@ export async function GET(request: NextRequest) {
if (response.status === 503 && attempt < MAX_RETRIES) {
console.warn(`⚠ Got 503 on attempt ${attempt}, retrying... (${url})`);
lastError = `503 on attempt ${attempt}`;
// Wait 500ms before retry
await new Promise(resolve => setTimeout(resolve, 500));
// Wait 100ms before retry
await new Promise(resolve => setTimeout(resolve, 100));
continue;
}
@@ -52,7 +52,7 @@ export async function GET(request: NextRequest) {
lastError = fetchError;
if (attempt < MAX_RETRIES) {
console.warn(`⚠ Fetch error on attempt ${attempt}, retrying...`, fetchError);
await new Promise(resolve => setTimeout(resolve, 500));
await new Promise(resolve => setTimeout(resolve, 100));
} else {
throw fetchError;
}
+1 -3
View File
@@ -33,9 +33,7 @@ export function SearchBox({ onSearch, onClear, initialQuery = '' }: SearchBoxPro
setQuery(selectedQuery);
onSearch(selectedQuery);
// Blur the input after selecting from history
setTimeout(() => {
inputRef.current?.blur();
}, 100);
inputRef.current?.blur();
});
// Update query when initialQuery changes
+1 -1
View File
@@ -5,7 +5,7 @@
const REQUEST_TIMEOUT = 15000;
const MAX_RETRIES = 3;
const RETRY_DELAY = 1000;
const RETRY_DELAY = 200;
/**
* Fetch with timeout support
+1 -1
View File
@@ -66,7 +66,7 @@ export function useHomePage() {
setHasSearched(true);
loadCachedResults(cached.results, cached.availableSources);
} else {
setTimeout(() => handleSearch(urlQuery), 100);
handleSearch(urlQuery);
}
}
}, [searchParams, loadFromCache, loadCachedResults]);