Skip to content

Commit

Permalink
fix: fix cache error with geo country mock (#4821)
Browse files Browse the repository at this point in the history
* fix: fix cache error with geo country mock

* fix: update caching logic

* fix: update caching logic

* fix: update caching logic

* fix: revert previous set mode to mock when using country flag

* chore: update contributors field

* Update src/lib/geo-location.js

Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>

* Update src/lib/geo-location.js

Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>

* chore: run prettier

Co-authored-by: JWhist <JWhist@users.noreply.github.com>
Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>
  • Loading branch information
3 people committed Jul 20, 2022
1 parent c766d51 commit 419f447
Showing 1 changed file with 8 additions and 1 deletion.
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)) {
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

1 comment on commit 419f447

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

Package size: 221 MB

Please sign in to comment.