Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions docs/api-performance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# API calls and performance

## How we tested

We opened the deployed application at http://it2810-23.idi.ntnu.no/project1/
and inspected the Network tab in the browser's developer tools, then confirmed
the findings by tracking every request via the Resource Timing API
(`performance.getEntriesByType('resource')`), which records every request made
since the page loaded regardless of when we started watching.

We checked requests to the REST API (`countries.dev`) at each stage:

- On application start.
- While filtering by region, including switching back to "All regions".
- While changing the sort order.
- While navigating between countries with Previous/Next and the country
selector.
- After leaving the page idle for 10 seconds, to rule out polling or a
refetch loop.

## Findings

The application makes exactly **one** request to the REST API per session:

```
GET https://countries.dev/region/europe
```

This happens once when the app starts. Region filtering and sorting are both
done client-side on the already-fetched list — the "Region" dropdown filters
by subregion in memory, and "Sort by" reorders the same array — so neither
triggers a new request. Navigating between countries only changes which
already-fetched country is displayed. No additional requests occurred during
any of the above, and none occurred while idle.

## TanStack Query configuration

No changes were needed. The existing configuration in `src/lib/queryClient.ts`
already supports this:

- `staleTime: 5 * 60 * 1000` — fetched data is treated as fresh for 5 minutes,
so remounting the country list within that window doesn't refetch.
- `refetchOnWindowFocus: false` — switching tabs or windows doesn't trigger a
refetch.
- `retry: 1` — a failed request is retried once, not looped indefinitely.

Since there is only one query in the app (`useCountries`, keyed by region) and
the UI never changes the region it's called with, there is only ever one
active query, and it is never invalidated during normal use.