fix: idb is not available in firefox private mode [CW-2217] (#7524)

This commit is contained in:
Shivam Mishra
2023-07-14 13:35:30 +05:30
committed by GitHub
parent 9de2edd300
commit 59b1d59574

View File

@@ -18,6 +18,10 @@ class CacheEnabledApiClient extends ApiClient {
return this.getFromCache(); return this.getFromCache();
} }
return this.getFromNetwork();
}
getFromNetwork() {
return axios.get(this.url); return axios.get(this.url);
} }
@@ -32,7 +36,12 @@ class CacheEnabledApiClient extends ApiClient {
} }
async getFromCache() { async getFromCache() {
await this.dataManager.initDb(); try {
// IDB is not supported in Firefox private mode: https://bugzilla.mozilla.org/show_bug.cgi?id=781982
await this.dataManager.initDb();
} catch {
return this.getFromNetwork();
}
const { data } = await axios.get( const { data } = await axios.get(
`/api/v1/accounts/${this.accountIdFromRoute}/cache_keys` `/api/v1/accounts/${this.accountIdFromRoute}/cache_keys`
@@ -55,16 +64,22 @@ class CacheEnabledApiClient extends ApiClient {
} }
async refetchAndCommit(newKey = null) { async refetchAndCommit(newKey = null) {
await this.dataManager.initDb(); const response = await this.getFromNetwork();
const response = await axios.get(this.url);
this.dataManager.replace({
modelName: this.cacheModelName,
data: this.extractDataFromResponse(response),
});
await this.dataManager.setCacheKeys({ try {
[this.cacheModelName]: newKey, await this.dataManager.initDb();
});
this.dataManager.replace({
modelName: this.cacheModelName,
data: this.extractDataFromResponse(response),
});
await this.dataManager.setCacheKeys({
[this.cacheModelName]: newKey,
});
} catch {
// Ignore error
}
return response; return response;
} }