refactored all mentions of "history" to "revision"

This commit is contained in:
azivner
2018-03-25 20:52:38 -04:00
parent a69d8737ce
commit 47eb1e3e02
22 changed files with 147 additions and 149 deletions

View File

@@ -3,7 +3,7 @@
const build = require('./build');
const packageJson = require('../../package');
const APP_DB_VERSION = 80;
const APP_DB_VERSION = 81;
module.exports = {
app_version: packageJson.version,

View File

@@ -161,7 +161,7 @@ async function runAllChecks() {
note_revisions LEFT JOIN notes USING(noteId)
WHERE
notes.noteId IS NULL`,
"Missing notes records for following note history ID > note ID", errorList);
"Missing notes records for following note revision ID > note ID", errorList);
await runCheck(`
SELECT

View File

@@ -154,32 +154,32 @@ async function protectNote(note, dataKey, protect, sourceId) {
await sync_table.addNoteSync(note.noteId, sourceId);
}
await protectNoteHistory(note.noteId, dataKey, protect, sourceId);
await protectNoteRevisions(note.noteId, dataKey, protect, sourceId);
}
async function protectNoteHistory(noteId, dataKey, protect, sourceId) {
const historyToChange = await sql.getRows("SELECT * FROM note_revisions WHERE noteId = ? AND isProtected != ?", [noteId, protect]);
async function protectNoteRevisions(noteId, dataKey, protect, sourceId) {
const revisionsToChange = await sql.getRows("SELECT * FROM note_revisions WHERE noteId = ? AND isProtected != ?", [noteId, protect]);
for (const history of historyToChange) {
for (const revision of revisionsToChange) {
if (protect) {
protected_session.encryptNoteHistoryRow(dataKey, history);
protected_session.encryptNoteRevision(dataKey, revision);
history.isProtected = true;
revision.isProtected = true;
}
else {
protected_session.decryptNoteHistoryRow(dataKey, history);
protected_session.decryptNoteRevision(dataKey, revision);
history.isProtected = false;
revision.isProtected = false;
}
await sql.execute("UPDATE note_revisions SET title = ?, content = ?, isProtected = ? WHERE noteRevisionId = ?",
[history.title, history.content, history.isProtected, history.noteRevisionId]);
[revision.title, revision.content, revision.isProtected, revision.noteRevisionId]);
await sync_table.addNoteHistorySync(history.noteRevisionId, sourceId);
await sync_table.addNoteRevisionSync(revision.noteRevisionId, sourceId);
}
}
async function saveNoteHistory(noteId, dataKey, sourceId, nowStr) {
async function saveNoteRevision(noteId, dataKey, sourceId, nowStr) {
const oldNote = await sql.getRow("SELECT * FROM notes WHERE noteId = ?", [noteId]);
if (oldNote.type === 'file') {
@@ -200,12 +200,12 @@ async function saveNoteHistory(noteId, dataKey, sourceId, nowStr) {
// title and text should be decrypted now
title: oldNote.title,
content: oldNote.content,
isProtected: 0, // will be fixed in the protectNoteHistory() call
isProtected: 0, // will be fixed in the protectNoteRevisions() call
dateModifiedFrom: oldNote.dateModified,
dateModifiedTo: nowStr
});
await sync_table.addNoteHistorySync(newNoteRevisionId, sourceId);
await sync_table.addNoteRevisionSync(newNoteRevisionId, sourceId);
}
async function saveNoteImages(noteId, noteText, sourceId) {
@@ -279,26 +279,26 @@ async function updateNote(noteId, newNote, dataKey, sourceId) {
const now = new Date();
const nowStr = utils.nowDate();
const historySnapshotTimeInterval = parseInt(await options.getOption('history_snapshot_time_interval'));
const noteRevisionSnapshotTimeInterval = parseInt(await options.getOption('note_revision_snapshot_time_interval'));
const historyCutoff = utils.dateStr(new Date(now.getTime() - historySnapshotTimeInterval * 1000));
const revisionCutoff = utils.dateStr(new Date(now.getTime() - noteRevisionSnapshotTimeInterval * 1000));
const existingnoteRevisionId = await sql.getValue(
"SELECT noteRevisionId FROM note_revisions WHERE noteId = ? AND dateModifiedTo >= ?", [noteId, historyCutoff]);
"SELECT noteRevisionId FROM note_revisions WHERE noteId = ? AND dateModifiedTo >= ?", [noteId, revisionCutoff]);
await sql.doInTransaction(async () => {
const msSinceDateCreated = now.getTime() - utils.parseDateTime(newNote.detail.dateCreated).getTime();
if (labelsMap.disable_versioning !== 'true'
&& !existingnoteRevisionId
&& msSinceDateCreated >= historySnapshotTimeInterval * 1000) {
&& msSinceDateCreated >= noteRevisionSnapshotTimeInterval * 1000) {
await saveNoteHistory(noteId, dataKey, sourceId, nowStr);
await saveNoteRevision(noteId, dataKey, sourceId, nowStr);
}
await saveNoteImages(noteId, newNote.detail.content, sourceId);
await protectNoteHistory(noteId, dataKey, newNote.detail.isProtected);
await protectNoteRevisions(noteId, dataKey, newNote.detail.isProtected);
await sql.execute("UPDATE notes SET title = ?, content = ?, isProtected = ?, dateModified = ? WHERE noteId = ?", [
newNote.detail.title,

View File

@@ -76,7 +76,7 @@ async function initOptions(startNotePath) {
await createOption('start_note_path', startNotePath, false);
await createOption('protected_session_timeout', 600, true);
await createOption('history_snapshot_time_interval', 600, true);
await createOption('note_revision_snapshot_time_interval', 600, true);
await createOption('last_backup_date', utils.nowDate(), false);
await createOption('db_version', app_info.db_version, false);

View File

@@ -75,7 +75,7 @@ function decryptNotes(dataKey, notes) {
}
}
function decryptNoteHistoryRow(dataKey, hist) {
function decryptNoteRevision(dataKey, hist) {
dataKey = getDataKey(dataKey);
if (!hist.isProtected) {
@@ -91,11 +91,11 @@ function decryptNoteHistoryRow(dataKey, hist) {
}
}
function decryptNoteHistoryRows(dataKey, historyRows) {
function decryptNoteRevisions(dataKey, noteRevisions) {
dataKey = getDataKey(dataKey);
for (const hist of historyRows) {
decryptNoteHistoryRow(dataKey, hist);
for (const revision of noteRevisions) {
decryptNoteRevision(dataKey, revision);
}
}
@@ -106,11 +106,11 @@ function encryptNote(dataKey, note) {
note.content = data_encryption.encrypt(dataKey, data_encryption.noteContentIv(note.noteId), note.content);
}
function encryptNoteHistoryRow(dataKey, history) {
function encryptNoteRevision(dataKey, revision) {
dataKey = getDataKey(dataKey);
history.title = data_encryption.encrypt(dataKey, data_encryption.noteTitleIv(history.noteRevisionId), history.title);
history.content = data_encryption.encrypt(dataKey, data_encryption.noteContentIv(history.noteRevisionId), history.content);
revision.title = data_encryption.encrypt(dataKey, data_encryption.noteTitleIv(revision.noteRevisionId), revision.title);
revision.content = data_encryption.encrypt(dataKey, data_encryption.noteContentIv(revision.noteRevisionId), revision.content);
}
module.exports = {
@@ -120,8 +120,8 @@ module.exports = {
isProtectedSessionAvailable,
decryptNote,
decryptNotes,
decryptNoteHistoryRow,
decryptNoteHistoryRows,
decryptNoteRevision,
decryptNoteRevisions,
encryptNote,
encryptNoteHistoryRow
encryptNoteRevision
};

View File

@@ -129,7 +129,7 @@ async function pullSync(syncContext) {
await syncUpdate.updateBranch(resp, syncContext.sourceId);
}
else if (sync.entityName === 'note_revisions') {
await syncUpdate.updateNoteHistory(resp, syncContext.sourceId);
await syncUpdate.updateNoteRevision(resp, syncContext.sourceId);
}
else if (sync.entityName === 'note_reordering') {
await syncUpdate.updateNoteReordering(resp, syncContext.sourceId);

View File

@@ -16,7 +16,7 @@ async function addNoteReorderingSync(parentNoteId, sourceId) {
await addEntitySync("note_reordering", parentNoteId, sourceId)
}
async function addNoteHistorySync(noteRevisionId, sourceId) {
async function addNoteRevisionSync(noteRevisionId, sourceId) {
await addEntitySync("note_revisions", noteRevisionId, sourceId);
}
@@ -104,7 +104,7 @@ module.exports = {
addNoteSync,
addBranchSync,
addNoteReorderingSync,
addNoteHistorySync,
addNoteRevisionSync,
addOptionsSync,
addRecentNoteSync,
addImageSync,

View File

@@ -42,18 +42,18 @@ async function updateBranch(entity, sourceId) {
});
}
async function updateNoteHistory(entity, sourceId) {
async function updateNoteRevision(entity, sourceId) {
const orig = await sql.getRowOrNull("SELECT * FROM note_revisions WHERE noteRevisionId = ?", [entity.noteRevisionId]);
await sql.doInTransaction(async () => {
// we update note history even if date modified to is the same because the only thing which might have changed
// we update note revision even if date modified to is the same because the only thing which might have changed
// is the protected status (and correnspondingly title and content) which doesn't affect the dateModifiedTo
if (orig === null || orig.dateModifiedTo <= entity.dateModifiedTo) {
await sql.replace('note_revisions', entity);
await sync_table.addNoteHistorySync(entity.noteRevisionId, sourceId);
await sync_table.addNoteRevisionSync(entity.noteRevisionId, sourceId);
log.info("Update/sync note history " + entity.noteRevisionId);
log.info("Update/sync note revision " + entity.noteRevisionId);
}
});
}
@@ -161,7 +161,7 @@ async function updateApiToken(entity, sourceId) {
module.exports = {
updateNote,
updateBranch,
updateNoteHistory,
updateNoteRevision,
updateNoteReordering,
updateOptions,
updateRecentNotes,