diff --git a/.jules/bolt.md b/.jules/bolt.md index 91541609..2c22390a 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -9,3 +9,7 @@ **Learning:** Using `on:keyup` for search input debouncing triggers unnecessary API calls on navigation keys (arrows, home, end) and misses changes from paste/cut. Svelte's reactive statements `$: debounce(value)` provide a robust, declarative way to trigger debouncing only when the value actually changes. **Action:** Replace `on:keyup` handlers with reactive statements for input debouncing to improve performance and correctness. + +## 2024-10-25 - Avoid waterfall in metaNamesSdk +**Learning:** Sequential await operations involving `metaNamesSdk.domainRepository.count()`, `getOwners()`, and `getRecentDomains()` cause a waterfall latency, especially when communicating with the blockchain context or external services. +**Action:** Since these fetches are completely independent of each other, group them up and run them concurrently using `Promise.all` to save on round-trips latency and reduce execution time. diff --git a/src/lib/server/index.ts b/src/lib/server/index.ts index d87bacec..649a9682 100644 --- a/src/lib/server/index.ts +++ b/src/lib/server/index.ts @@ -44,11 +44,13 @@ export interface DomainStats { } export const getStats = async (): Promise => { - const domainCount = await metaNamesSdk.domainRepository.count(); - const ownerCount = await metaNamesSdk.domainRepository - .getOwners() - .then((owners) => owners.length); - const recentDomains = await getRecentDomains(); + // ⚡ Bolt: Execute independent async operations concurrently using Promise.all + // to avoid waterfall latency and significantly reduce total execution time. + const [domainCount, ownerCount, recentDomains] = await Promise.all([ + metaNamesSdk.domainRepository.count(), + metaNamesSdk.domainRepository.getOwners().then((owners) => owners.length), + getRecentDomains() + ]); return { domainCount,