Skip to content

Commit

Permalink
debug: show debugging information, more chunks, wait between chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
th0rgall committed Mar 13, 2024
1 parent 06df037 commit 5c66204
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lib/api/garden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<void>((resolve) => setTimeout(() => resolve(), 2000));
} while (startAfterDoc != null && iteration < LOOP_LIMIT_ITEMS / CHUNK_SIZE);

isFetchingGardens.set(false);
Expand Down
16 changes: 16 additions & 0 deletions src/routes/explore/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
carNoticeShown = false;
};
let fetchError = '';
// LIFECYCLE HOOKS
onMount(async () => {
Expand All @@ -151,6 +153,7 @@
await getAllListedGardens();
} catch (ex) {
console.error(ex);
fetchError = 'Error' + ex;
isFetchingGardens.set(false);
}
}
Expand Down Expand Up @@ -210,6 +213,10 @@
<FileTrails />
<TrainconnectionsLayer />
<ZoomRestrictionNotice />
<div class="garden-debug">
{Object.keys($allGardens).length} gardens
{fetchError}
</div>
</Map>
<LayersAndTools
bind:showHiking
Expand All @@ -234,6 +241,15 @@
</div>

<style>
.garden-debug {
font-size: 2rem;
position: absolute;
bottom: 50%;
right: 0;
background: white;
padding: 0.5rem;
}
.map-section {
width: 100%;
height: 100%;
Expand Down

0 comments on commit 5c66204

Please sign in to comment.