added flag for the erased notes

This commit is contained in:
zadam
2019-11-01 22:09:51 +01:00
parent 2e58e32112
commit 2af86927b0
9 changed files with 107 additions and 25 deletions

View File

@@ -23,6 +23,7 @@ const RELATION_DEFINITION = 'relation-definition';
* @property {string} title - note title
* @property {boolean} isProtected - true if note is protected
* @property {boolean} isDeleted - true if note is deleted
* @property {boolean} isErased - true if note's content is erased after it has been deleted
* @property {string} dateCreated - local date time (with offset)
* @property {string} dateModified - local date time (with offset)
* @property {string} utcDateCreated

View File

@@ -4,7 +4,7 @@ const build = require('./build');
const packageJson = require('../../package');
const {TRILIUM_DATA_DIR} = require('./data_dir');
const APP_DB_VERSION = 150;
const APP_DB_VERSION = 151;
const SYNC_VERSION = 11;
const CLIPPER_PROTOCOL_VERSION = "1.0";

View File

@@ -228,6 +228,23 @@ async function findLogicIssues() {
AND content IS NULL`,
({noteId}) => `Note ${noteId} content is null even though it is not deleted`);
await findIssues(`
SELECT noteId
FROM notes
JOIN note_contents USING(noteId)
WHERE
isErased = 1
AND content IS NOT NULL`,
({noteId}) => `Note ${noteId} content is not null even though the note is erased`);
await findIssues(`
SELECT noteId
FROM notes
WHERE
isErased = 1
AND isDeleted = 0`,
({noteId}) => `Note ${noteId} is not deleted even though it is erased`);
await findIssues(`
SELECT parentNoteId
FROM

View File

@@ -457,15 +457,35 @@ async function scanForLinks(noteId) {
}
}
async function cleanupDeletedNotes() {
async function eraseDeletedNotes() {
const cutoffDate = new Date(Date.now() - 48 * 3600 * 1000);
const noteIdsToErase = await sql.getColumn("SELECT noteId FROM notes WHERE isDeleted = 1 AND isErased = 0 AND notes.utcDateModified <= ?", [dateUtils.utcDateStr(cutoffDate)]);
const utcNowDateTime = dateUtils.utcNowDateTime();
const localNowDateTime = dateUtils.localNowDateTime();
// it's better to not use repository for this because it will complain about saving protected notes
// out of protected session
await sql.execute("UPDATE note_contents SET content = NULL WHERE content IS NOT NULL AND noteId IN (SELECT noteId FROM notes WHERE isDeleted = 1 AND notes.utcDateModified <= ?)", [dateUtils.utcDateStr(cutoffDate)]);
await sql.executeMany(`
UPDATE notes
SET isErased = 1,
utcDateModified = '${utcNowDateTime}',
dateModified = '${localNowDateTime}'
WHERE noteId IN (???)`, noteIdsToErase);
await sql.execute("UPDATE note_revisions SET content = NULL WHERE note_revisions.content IS NOT NULL AND noteId IN (SELECT noteId FROM notes WHERE isDeleted = 1 AND notes.utcDateModified <= ?)", [dateUtils.utcDateStr(cutoffDate)]);
await sql.executeMany(`
UPDATE note_contents
SET content = NULL,
utcDateModified = '${utcNowDateTime}'
WHERE noteId IN (???)`, noteIdsToErase);
await sql.executeMany(`
UPDATE note_revisions
SET content = NULL,
utcDateModified = '${utcNowDateTime}'
WHERE noteId IN (???)`, noteIdsToErase);
}
async function duplicateNote(noteId, parentNoteId) {
@@ -508,9 +528,9 @@ async function duplicateNote(noteId, parentNoteId) {
sqlInit.dbReady.then(() => {
// first cleanup kickoff 5 minutes after startup
setTimeout(cls.wrap(cleanupDeletedNotes), 5 * 60 * 1000);
setTimeout(cls.wrap(eraseDeletedNotes), 5 * 60 * 1000);
setInterval(cls.wrap(cleanupDeletedNotes), 4 * 3600 * 1000);
setInterval(cls.wrap(eraseDeletedNotes), 4 * 3600 * 1000);
});
module.exports = {

View File

@@ -152,6 +152,11 @@ async function execute(query, params = []) {
return result;
}
async function executeMany(query, params) {
// essentially just alias
await getManyRows(query, params);
}
async function executeScript(query) {
return await wrap(async db => db.exec(query));
}
@@ -235,6 +240,7 @@ module.exports = {
getMap,
getColumn,
execute,
executeMany,
executeScript,
transactional,
upsert