Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix cache error with geo country mock #4821

Merged
merged 15 commits into from
Jul 20, 2022
9 changes: 8 additions & 1 deletion src/lib/geo-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,16 @@ const mockLocation = {
const getGeoLocation = async ({ geoCountry, mode, offline, state }) => {
const cacheObject = state.get(STATE_GEO_PROPERTY)

// If `--country` was used, we also set `--mode=mock`.
if (geoCountry) {
mode = 'mock'
}

// If we have cached geolocation data and the `--geo` option is set to
// `cache`, let's try to use it.
if (cacheObject !== undefined && mode === 'cache') {
// Or, if the country we're trying to mock is the same one as we have in the
// cache, let's use the cache instead of the mock.
if (cacheObject !== undefined && (mode === 'cache' || cacheObject.data.country.code === geoCountry)) {
JWhist marked this conversation as resolved.
Show resolved Hide resolved
const age = Date.now() - cacheObject.timestamp

// Let's use the cached data if it's not older than the TTL. Also, if the
Expand Down