Skip to content

Look up the API country names once per client - #1593

Merged
frenck merged 1 commit into
mainfrom
frenck/cache-api-country-names
Oct 2, 2026
Merged

frenck merged 1 commit into
mainfrom
frenck/cache-api-country-names

Conversation

@frenck

@frenck frenck commented Oct 2, 2026

Copy link
Copy Markdown
Owner

Breaking change

None.

Proposed change

Found while comparing with other Radio Browser clients. Every states(country_code=...) call (#1586) fetched the whole /json/countries list, around 246 entries, just to translate one country code into the name the API uses for it. Right now a single server carries all of the API's traffic, so it is worth not asking twice.

The translation is now kept on the client, so only the first states() call with a country code fetches the list. Those names hardly ever change, so the cache lives as long as the client. A broken response is not cached, so the next call simply tries again.

Type of change

  • Dependency or tooling upgrade
  • Bugfix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Deprecation (replaces or removes a feature, with a migration path)
  • Breaking change (a fix or feature that changes existing behavior)
  • Code quality, refactor, or test-only change
  • Documentation only

Additional information

Checklist

  • I fully understand the code in this pull request and can explain every line, including any AI-assisted changes.
  • The change is covered by tests, and poetry run pytest passes locally. A pull request cannot be merged unless CI is green.
  • poetry run prek run --all-files passes (lint, format, and type checks).
  • No commented-out or dead code is left in the pull request.

states() fetched the whole country list on every call with a country
code, just to translate that one code. Keep the names on the client.
@frenck frenck added the enhancement Enhancement of the code, not introducing new features. label Oct 2, 2026
@frenck
frenck merged commit 9c77569 into main Oct 2, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Enhancement of the code, not introducing new features.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant