Merge pull request #2840 from jryans/storage-fallback
Handle storage fallback cases in consistency check
This commit is contained in:
commit
3cd4b6992d
1 changed files with 46 additions and 16 deletions
|
@ -15,6 +15,7 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Matrix from 'matrix-js-sdk';
|
import Matrix from 'matrix-js-sdk';
|
||||||
|
import LocalStorageCryptoStore from 'matrix-js-sdk/lib/crypto/store/localStorage-crypto-store';
|
||||||
import Analytics from '../Analytics';
|
import Analytics from '../Analytics';
|
||||||
|
|
||||||
const localStorage = window.localStorage;
|
const localStorage = window.localStorage;
|
||||||
|
@ -61,15 +62,9 @@ export async function checkConsistency() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (indexedDB && localStorage) {
|
if (indexedDB && localStorage) {
|
||||||
try {
|
const results = await checkSyncStore();
|
||||||
const dataInSyncStore = await Matrix.IndexedDBStore.exists(
|
if (!results.healthy) {
|
||||||
indexedDB, SYNC_STORE_NAME,
|
|
||||||
);
|
|
||||||
log(`Sync store contains data? ${dataInSyncStore}`);
|
|
||||||
} catch (e) {
|
|
||||||
healthy = false;
|
healthy = false;
|
||||||
error("Sync store inaccessible", e);
|
|
||||||
track("Sync store inaccessible");
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
healthy = false;
|
healthy = false;
|
||||||
|
@ -78,15 +73,10 @@ export async function checkConsistency() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (indexedDB) {
|
if (indexedDB) {
|
||||||
try {
|
const results = await checkCryptoStore();
|
||||||
dataInCryptoStore = await Matrix.IndexedDBCryptoStore.exists(
|
dataInCryptoStore = results.exists;
|
||||||
indexedDB, CRYPTO_STORE_NAME,
|
if (!results.healthy) {
|
||||||
);
|
|
||||||
log(`Crypto store contains data? ${dataInCryptoStore}`);
|
|
||||||
} catch (e) {
|
|
||||||
healthy = false;
|
healthy = false;
|
||||||
error("Crypto store inaccessible", e);
|
|
||||||
track("Crypto store inaccessible");
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
healthy = false;
|
healthy = false;
|
||||||
|
@ -111,3 +101,43 @@ export async function checkConsistency() {
|
||||||
track("Consistency checks failed");
|
track("Consistency checks failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function checkSyncStore() {
|
||||||
|
let exists = false;
|
||||||
|
try {
|
||||||
|
exists = await Matrix.IndexedDBStore.exists(
|
||||||
|
indexedDB, SYNC_STORE_NAME,
|
||||||
|
);
|
||||||
|
log(`Sync store using IndexedDB contains data? ${exists}`);
|
||||||
|
return { exists, healthy: true };
|
||||||
|
} catch (e) {
|
||||||
|
error("Sync store using IndexedDB inaccessible", e);
|
||||||
|
track("Sync store using IndexedDB inaccessible");
|
||||||
|
}
|
||||||
|
log("Sync store using memory only");
|
||||||
|
return { exists, healthy: false };
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkCryptoStore() {
|
||||||
|
let exists = false;
|
||||||
|
try {
|
||||||
|
exists = await Matrix.IndexedDBCryptoStore.exists(
|
||||||
|
indexedDB, CRYPTO_STORE_NAME,
|
||||||
|
);
|
||||||
|
log(`Crypto store using IndexedDB contains data? ${exists}`);
|
||||||
|
return { exists, healthy: true };
|
||||||
|
} catch (e) {
|
||||||
|
error("Crypto store using IndexedDB inaccessible", e);
|
||||||
|
track("Crypto store using IndexedDB inaccessible");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
exists = await LocalStorageCryptoStore.exists(localStorage);
|
||||||
|
log(`Crypto store using local storage contains data? ${exists}`);
|
||||||
|
return { exists, healthy: true };
|
||||||
|
} catch (e) {
|
||||||
|
error("Crypto store using local storage inaccessible", e);
|
||||||
|
track("Crypto store using local storage inaccessible");
|
||||||
|
}
|
||||||
|
log("Crypto store using memory only");
|
||||||
|
return { exists, healthy: false };
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue