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;
|
||||
|
||||
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) {
|
||||
throw new Error('initialze: Already initialized!');
|
||||
}
|
||||
|
@ -29,8 +30,19 @@ async function initialize({ configDir }) {
|
|||
event.sender.send(`${ERASE_ATTACHMENTS_KEY}-done`);
|
||||
} catch (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);
|
||||
}
|
||||
});
|
||||
|
||||
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');
|
||||
|
||||
if (newVersion) {
|
||||
await window.Signal.Data.cleanupOrphanedAttachments();
|
||||
}
|
||||
|
||||
Views.Initialization.setMessage(window.i18n('loading'));
|
||||
|
||||
// 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 ERASE_SQL_KEY = 'erase-sql-key';
|
||||
const ERASE_ATTACHMENTS_KEY = 'erase-attachments';
|
||||
const CLEANUP_ORPHANED_ATTACHMENTS_KEY = 'cleanup-orphaned-attachments';
|
||||
|
||||
const _jobs = Object.create(null);
|
||||
const _DEBUG = false;
|
||||
|
@ -64,6 +65,7 @@ module.exports = {
|
|||
|
||||
removeAll,
|
||||
removeOtherData,
|
||||
cleanupOrphanedAttachments,
|
||||
|
||||
// Returning plain JSON
|
||||
getMessagesNeedingUpgrade,
|
||||
|
@ -388,6 +390,10 @@ async function 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
|
||||
async function removeOtherData() {
|
||||
await Promise.all([
|
||||
|
|
25
main.js
25
main.js
|
@ -26,7 +26,7 @@ const packageJson = require('./package.json');
|
|||
|
||||
const sql = require('./app/sql');
|
||||
const sqlChannels = require('./app/sql_channel');
|
||||
// const attachments = require('./app/attachments');
|
||||
const attachments = require('./app/attachments');
|
||||
const attachmentChannel = require('./app/attachment_channel');
|
||||
const autoUpdate = require('./app/auto_update');
|
||||
const createTrayIcon = require('./app/tray_icon');
|
||||
|
@ -618,8 +618,6 @@ app.on('ready', async () => {
|
|||
locale = loadLocale({ appLocale, logger });
|
||||
}
|
||||
|
||||
await attachmentChannel.initialize({ configDir: userDataPath });
|
||||
|
||||
let key = userConfig.get('key');
|
||||
if (!key) {
|
||||
// https://www.zetetic.net/sqlcipher/sqlcipher-api/#key
|
||||
|
@ -630,12 +628,21 @@ app.on('ready', async () => {
|
|||
await sql.initialize({ configDir: userDataPath, key });
|
||||
await sqlChannels.initialize({ userConfig });
|
||||
|
||||
// const allAttachments = await attachments.getAllAttachments(userDataPath);
|
||||
// const orphanedAttachments = await sql.removeKnownAttachments(allAttachments);
|
||||
// await attachments.deleteAll({
|
||||
// userDataPath,
|
||||
// attachments: orphanedAttachments,
|
||||
// });
|
||||
async function cleanupOrphanedAttachments() {
|
||||
const allAttachments = await attachments.getAllAttachments(userDataPath);
|
||||
const orphanedAttachments = await sql.removeKnownAttachments(
|
||||
allAttachments
|
||||
);
|
||||
await attachments.deleteAll({
|
||||
userDataPath,
|
||||
attachments: orphanedAttachments,
|
||||
});
|
||||
}
|
||||
|
||||
await attachmentChannel.initialize({
|
||||
configDir: userDataPath,
|
||||
cleanupOrphanedAttachments,
|
||||
});
|
||||
|
||||
ready = true;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue