Re-enable orphaned attachment cleanup
This commit is contained in:
parent
15751f3521
commit
9f920aa35b
4 changed files with 40 additions and 11 deletions
|
@ -11,8 +11,9 @@ module.exports = {
|
||||||
let initialized = false;
|
let initialized = false;
|
||||||
|
|
||||||
const ERASE_ATTACHMENTS_KEY = 'erase-attachments';
|
const ERASE_ATTACHMENTS_KEY = 'erase-attachments';
|
||||||
|
const CLEANUP_ORPHANED_ATTACHMENTS_KEY = 'cleanup-orphaned-attachments';
|
||||||
|
|
||||||
async function initialize({ configDir }) {
|
async function initialize({ configDir, cleanupOrphanedAttachments }) {
|
||||||
if (initialized) {
|
if (initialized) {
|
||||||
throw new Error('initialze: Already initialized!');
|
throw new Error('initialze: Already initialized!');
|
||||||
}
|
}
|
||||||
|
@ -29,8 +30,19 @@ async function initialize({ configDir }) {
|
||||||
event.sender.send(`${ERASE_ATTACHMENTS_KEY}-done`);
|
event.sender.send(`${ERASE_ATTACHMENTS_KEY}-done`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorForDisplay = error && error.stack ? error.stack : error;
|
const errorForDisplay = error && error.stack ? error.stack : error;
|
||||||
console.log(`sql-erase error: ${errorForDisplay}`);
|
console.log(`erase attachments error: ${errorForDisplay}`);
|
||||||
event.sender.send(`${ERASE_ATTACHMENTS_KEY}-done`, error);
|
event.sender.send(`${ERASE_ATTACHMENTS_KEY}-done`, error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcMain.on(CLEANUP_ORPHANED_ATTACHMENTS_KEY, async event => {
|
||||||
|
try {
|
||||||
|
await cleanupOrphanedAttachments();
|
||||||
|
event.sender.send(`${CLEANUP_ORPHANED_ATTACHMENTS_KEY}-done`);
|
||||||
|
} catch (error) {
|
||||||
|
const errorForDisplay = error && error.stack ? error.stack : error;
|
||||||
|
console.log(`cleanup orphaned attachments error: ${errorForDisplay}`);
|
||||||
|
event.sender.send(`${CLEANUP_ORPHANED_ATTACHMENTS_KEY}-done`, error);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -408,6 +408,10 @@
|
||||||
);
|
);
|
||||||
window.log.info('Cleanup: complete');
|
window.log.info('Cleanup: complete');
|
||||||
|
|
||||||
|
if (newVersion) {
|
||||||
|
await window.Signal.Data.cleanupOrphanedAttachments();
|
||||||
|
}
|
||||||
|
|
||||||
Views.Initialization.setMessage(window.i18n('loading'));
|
Views.Initialization.setMessage(window.i18n('loading'));
|
||||||
|
|
||||||
// Note: We are not invoking the second set of IndexedDB migrations because it is
|
// Note: We are not invoking the second set of IndexedDB migrations because it is
|
||||||
|
|
|
@ -22,6 +22,7 @@ const DATABASE_UPDATE_TIMEOUT = 2 * 60 * 1000; // two minutes
|
||||||
const SQL_CHANNEL_KEY = 'sql-channel';
|
const SQL_CHANNEL_KEY = 'sql-channel';
|
||||||
const ERASE_SQL_KEY = 'erase-sql-key';
|
const ERASE_SQL_KEY = 'erase-sql-key';
|
||||||
const ERASE_ATTACHMENTS_KEY = 'erase-attachments';
|
const ERASE_ATTACHMENTS_KEY = 'erase-attachments';
|
||||||
|
const CLEANUP_ORPHANED_ATTACHMENTS_KEY = 'cleanup-orphaned-attachments';
|
||||||
|
|
||||||
const _jobs = Object.create(null);
|
const _jobs = Object.create(null);
|
||||||
const _DEBUG = false;
|
const _DEBUG = false;
|
||||||
|
@ -64,6 +65,7 @@ module.exports = {
|
||||||
|
|
||||||
removeAll,
|
removeAll,
|
||||||
removeOtherData,
|
removeOtherData,
|
||||||
|
cleanupOrphanedAttachments,
|
||||||
|
|
||||||
// Returning plain JSON
|
// Returning plain JSON
|
||||||
getMessagesNeedingUpgrade,
|
getMessagesNeedingUpgrade,
|
||||||
|
@ -388,6 +390,10 @@ async function removeAll() {
|
||||||
await channels.removeAll();
|
await channels.removeAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function cleanupOrphanedAttachments() {
|
||||||
|
await callChannel(CLEANUP_ORPHANED_ATTACHMENTS_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
// Note: will need to restart the app after calling this, to set up afresh
|
// Note: will need to restart the app after calling this, to set up afresh
|
||||||
async function removeOtherData() {
|
async function removeOtherData() {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
|
|
25
main.js
25
main.js
|
@ -26,7 +26,7 @@ const packageJson = require('./package.json');
|
||||||
|
|
||||||
const sql = require('./app/sql');
|
const sql = require('./app/sql');
|
||||||
const sqlChannels = require('./app/sql_channel');
|
const sqlChannels = require('./app/sql_channel');
|
||||||
// const attachments = require('./app/attachments');
|
const attachments = require('./app/attachments');
|
||||||
const attachmentChannel = require('./app/attachment_channel');
|
const attachmentChannel = require('./app/attachment_channel');
|
||||||
const autoUpdate = require('./app/auto_update');
|
const autoUpdate = require('./app/auto_update');
|
||||||
const createTrayIcon = require('./app/tray_icon');
|
const createTrayIcon = require('./app/tray_icon');
|
||||||
|
@ -618,8 +618,6 @@ app.on('ready', async () => {
|
||||||
locale = loadLocale({ appLocale, logger });
|
locale = loadLocale({ appLocale, logger });
|
||||||
}
|
}
|
||||||
|
|
||||||
await attachmentChannel.initialize({ configDir: userDataPath });
|
|
||||||
|
|
||||||
let key = userConfig.get('key');
|
let key = userConfig.get('key');
|
||||||
if (!key) {
|
if (!key) {
|
||||||
// https://www.zetetic.net/sqlcipher/sqlcipher-api/#key
|
// https://www.zetetic.net/sqlcipher/sqlcipher-api/#key
|
||||||
|
@ -630,12 +628,21 @@ app.on('ready', async () => {
|
||||||
await sql.initialize({ configDir: userDataPath, key });
|
await sql.initialize({ configDir: userDataPath, key });
|
||||||
await sqlChannels.initialize({ userConfig });
|
await sqlChannels.initialize({ userConfig });
|
||||||
|
|
||||||
// const allAttachments = await attachments.getAllAttachments(userDataPath);
|
async function cleanupOrphanedAttachments() {
|
||||||
// const orphanedAttachments = await sql.removeKnownAttachments(allAttachments);
|
const allAttachments = await attachments.getAllAttachments(userDataPath);
|
||||||
// await attachments.deleteAll({
|
const orphanedAttachments = await sql.removeKnownAttachments(
|
||||||
// userDataPath,
|
allAttachments
|
||||||
// attachments: orphanedAttachments,
|
);
|
||||||
// });
|
await attachments.deleteAll({
|
||||||
|
userDataPath,
|
||||||
|
attachments: orphanedAttachments,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await attachmentChannel.initialize({
|
||||||
|
configDir: userDataPath,
|
||||||
|
cleanupOrphanedAttachments,
|
||||||
|
});
|
||||||
|
|
||||||
ready = true;
|
ready = true;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue