Show and log progress during the SQLCipher migration
This commit is contained in:
parent
6b78f2582b
commit
1d7987108b
7 changed files with 98 additions and 24 deletions
|
@ -134,7 +134,7 @@ exports.dangerouslyProcessAllWithoutIndex = async ({
|
|||
// NOTE: Even if we make this async using `then`, requesting `count` on an
|
||||
// IndexedDB store blocks all subsequent transactions, so we might as well
|
||||
// explicitly wait for it here:
|
||||
const numTotalMessages = await _getNumMessages({ connection });
|
||||
const numTotalMessages = await exports.getNumMessages({ connection });
|
||||
|
||||
const migrationStartTime = Date.now();
|
||||
let numCumulativeMessagesProcessed = 0;
|
||||
|
@ -366,7 +366,7 @@ const _dangerouslyFetchMessagesRequiringSchemaUpgradeWithoutIndex = ({
|
|||
});
|
||||
};
|
||||
|
||||
const _getNumMessages = async ({ connection } = {}) => {
|
||||
exports.getNumMessages = async ({ connection } = {}) => {
|
||||
if (!isObject(connection)) {
|
||||
throw new TypeError("'connection' is required");
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ const {
|
|||
const {
|
||||
getMessageExportLastIndex,
|
||||
setMessageExportLastIndex,
|
||||
getMessageExportCount,
|
||||
setMessageExportCount,
|
||||
getUnprocessedExportLastIndex,
|
||||
setUnprocessedExportLastIndex,
|
||||
} = require('./settings');
|
||||
|
@ -18,7 +20,12 @@ module.exports = {
|
|||
migrateToSQL,
|
||||
};
|
||||
|
||||
async function migrateToSQL({ db, clearStores, handleDOMException }) {
|
||||
async function migrateToSQL({
|
||||
db,
|
||||
clearStores,
|
||||
handleDOMException,
|
||||
countCallback,
|
||||
}) {
|
||||
if (!db) {
|
||||
throw new Error('Need db for IndexedDB connection!');
|
||||
}
|
||||
|
@ -31,7 +38,10 @@ async function migrateToSQL({ db, clearStores, handleDOMException }) {
|
|||
|
||||
window.log.info('migrateToSQL: start');
|
||||
|
||||
let lastIndex = await getMessageExportLastIndex(db);
|
||||
let [lastIndex, doneSoFar] = await Promise.all([
|
||||
getMessageExportLastIndex(db),
|
||||
getMessageExportCount(db),
|
||||
]);
|
||||
let complete = false;
|
||||
|
||||
while (!complete) {
|
||||
|
@ -48,7 +58,16 @@ async function migrateToSQL({ db, clearStores, handleDOMException }) {
|
|||
({ complete, lastIndex } = status);
|
||||
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await setMessageExportLastIndex(db, lastIndex);
|
||||
await Promise.all([
|
||||
setMessageExportCount(db, doneSoFar),
|
||||
setMessageExportLastIndex(db, lastIndex),
|
||||
]);
|
||||
|
||||
const { count } = status;
|
||||
doneSoFar += count;
|
||||
if (countCallback) {
|
||||
countCallback(doneSoFar);
|
||||
}
|
||||
}
|
||||
window.log.info('migrateToSQL: migrate of messages complete');
|
||||
|
||||
|
@ -85,7 +104,7 @@ async function migrateStoreToSQLite({
|
|||
storeName,
|
||||
handleDOMException,
|
||||
lastIndex = null,
|
||||
batchSize = 20,
|
||||
batchSize = 50,
|
||||
}) {
|
||||
if (!db) {
|
||||
throw new Error('Need db for IndexedDB connection!');
|
||||
|
|
|
@ -4,6 +4,7 @@ const ITEMS_STORE_NAME = 'items';
|
|||
const LAST_PROCESSED_INDEX_KEY = 'attachmentMigration_lastProcessedIndex';
|
||||
const IS_MIGRATION_COMPLETE_KEY = 'attachmentMigration_isComplete';
|
||||
const MESSAGE_LAST_INDEX_KEY = 'sqlMigration_messageLastIndex';
|
||||
const MESSAGE_COUNT_KEY = 'sqlMigration_messageCount';
|
||||
const UNPROCESSED_LAST_INDEX_KEY = 'sqlMigration_unprocessedLastIndex';
|
||||
|
||||
// Public API
|
||||
|
@ -25,6 +26,10 @@ exports.getMessageExportLastIndex = connection =>
|
|||
exports._getItem(connection, MESSAGE_LAST_INDEX_KEY);
|
||||
exports.setMessageExportLastIndex = (connection, lastIndex) =>
|
||||
exports._setItem(connection, MESSAGE_LAST_INDEX_KEY, lastIndex);
|
||||
exports.getMessageExportCount = connection =>
|
||||
exports._getItem(connection, MESSAGE_COUNT_KEY);
|
||||
exports.setMessageExportCount = (connection, count) =>
|
||||
exports._setItem(connection, MESSAGE_COUNT_KEY, count);
|
||||
|
||||
exports.getUnprocessedExportLastIndex = connection =>
|
||||
exports._getItem(connection, UNPROCESSED_LAST_INDEX_KEY);
|
||||
|
|
|
@ -2,26 +2,44 @@
|
|||
|
||||
/* global i18n: false */
|
||||
|
||||
const OPTIMIZATION_MESSAGE_DISPLAY_THRESHOLD = 1000; // milliseconds
|
||||
const DISPLAY_THRESHOLD = 3000; // milliseconds
|
||||
const SELECTOR = '.app-loading-screen .message';
|
||||
|
||||
const setMessage = () => {
|
||||
const message = document.querySelector('.app-loading-screen .message');
|
||||
if (!message) {
|
||||
return () => {};
|
||||
let timeout;
|
||||
let targetString;
|
||||
let didTimeout = false;
|
||||
|
||||
const clear = () => {
|
||||
if (timeout) {
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
}
|
||||
message.innerText = i18n('loading');
|
||||
};
|
||||
|
||||
const optimizingMessageTimeoutId = setTimeout(() => {
|
||||
const innerMessage = document.querySelector('.app-loading-screen .message');
|
||||
const setMessage = loadingText => {
|
||||
const message = document.querySelector(SELECTOR);
|
||||
if (!message) {
|
||||
return clear;
|
||||
}
|
||||
|
||||
targetString = loadingText || i18n('optimizingApplication');
|
||||
|
||||
message.innerText = didTimeout ? targetString : i18n('loading');
|
||||
|
||||
if (timeout) {
|
||||
return clear;
|
||||
}
|
||||
|
||||
timeout = setTimeout(() => {
|
||||
didTimeout = true;
|
||||
const innerMessage = document.querySelector(SELECTOR);
|
||||
if (!innerMessage) {
|
||||
return;
|
||||
}
|
||||
innerMessage.innerText = i18n('optimizingApplication');
|
||||
}, OPTIMIZATION_MESSAGE_DISPLAY_THRESHOLD);
|
||||
innerMessage.innerText = targetString;
|
||||
}, DISPLAY_THRESHOLD);
|
||||
|
||||
return () => {
|
||||
clearTimeout(optimizingMessageTimeoutId);
|
||||
};
|
||||
return clear;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue