Skip to content

Commit

Permalink
fix: Remove cache in geolocation quota cozy-client query
Browse files Browse the repository at this point in the history
**About the expected behavior**

We want to do this request until we have a timeserie. As soon as we have a timeserie, we do not need anymore to do this request.

I think this behavior is not possible to model in cozy-client.

So I do the request as long as the result is [], and then when there is a timeserie, I store the timeserie in AsyncStorage. And if there is a timeserie in AsyncStorage, I don't do the request.

**About this commit**

With the cozy-client store and 24 hours cache as before this commit, I could store [] in the cache which is NOT what I want.
  • Loading branch information
zatteo committed Jan 16, 2024
1 parent d03251f commit 20de1c9
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/app/domain/geolocation/helpers/quota.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { getData, storeData, StorageKeys } from '/libs/localStore/storage'
import { setGeolocationTracking } from '/app/domain/geolocation/services/tracking'

const MAX_DAYS_TO_CAPTURE_UNLIMITED = -1
const ONE_DAY = 24 * 60 * 60 * 1000

const log = Minilog('📍 Geolocation')

Expand Down Expand Up @@ -43,18 +42,14 @@ const getFirstTimeserie = async (
if (firstTimeserieCachedLocally) {
return firstTimeserieCachedLocally
} else {
const { data } = (await client.fetchQueryAndGetFromState({
definition: Q('io.cozy.timeseries.geojson')
const { data } = (await client.query(
Q('io.cozy.timeseries.geojson')
.where({ startDate: { $gt: null } })
.select(['_id', 'startDate'])
.indexFields(['startDate'])
.sortBy([{ startDate: 'asc' }])
.limitBy(1),
options: {
as: 'io.cozy.timeseries.geojson/firstTimeserie',
fetchPolicy: CozyClient.fetchPolicies.olderThan(ONE_DAY)
}
})) as unknown as { data: FirstTimeserie[] }
.limitBy(1)
)) as unknown as { data: FirstTimeserie[] }

if (data.length === 0) return undefined

Expand Down

0 comments on commit 20de1c9

Please sign in to comment.