diff --git a/src/lib/api/garden.ts b/src/lib/api/garden.ts index 282c7214..27102bd8 100644 --- a/src/lib/api/garden.ts +++ b/src/lib/api/garden.ts @@ -42,7 +42,7 @@ export const getGarden = async (id: string) => { }; export const getAllListedGardens = async () => { - const CHUNK_SIZE = 1000; + const CHUNK_SIZE = 500; // To prevent endless loops in case of unexpected problems or bugs // Note: this leads to the loop breaking once this number of gardens is reached! const LOOP_LIMIT_ITEMS = 100000; @@ -79,6 +79,9 @@ export const getAllListedGardens = async () => { allGardens.update((existingGardens) => Object.assign(!existingGardens ? {} : existingGardens, newGardens) ); + + // Wait 2 seconds before fetching the next chunk + await new Promise((resolve) => setTimeout(() => resolve(), 2000)); } while (startAfterDoc != null && iteration < LOOP_LIMIT_ITEMS / CHUNK_SIZE); isFetchingGardens.set(false); diff --git a/src/routes/explore/+layout.svelte b/src/routes/explore/+layout.svelte index d9190ed2..17a7a24b 100644 --- a/src/routes/explore/+layout.svelte +++ b/src/routes/explore/+layout.svelte @@ -132,6 +132,8 @@ carNoticeShown = false; }; + let fetchError = ''; + // LIFECYCLE HOOKS onMount(async () => { @@ -151,6 +153,7 @@ await getAllListedGardens(); } catch (ex) { console.error(ex); + fetchError = 'Error' + ex; isFetchingGardens.set(false); } } @@ -210,6 +213,10 @@ +
+ {Object.keys($allGardens).length} gardens + {fetchError} +