1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

All: Improved: Make sure a revision is saved a note has not been modified for over a week

This commit is contained in:
Laurent Cozic 2019-05-08 00:51:56 +01:00
parent a4db1bc671
commit 78372c9bac
3 changed files with 12 additions and 15 deletions

View File

@ -177,15 +177,14 @@ describe('services_Revision', function() {
expect(revNote3.title).toBe('hello John');
}));
it('should create a revision for notes that existed before the revision service, the first time it is saved', asyncTest(async () => {
it('should create a revision for notes that are older than a given interval', asyncTest(async () => {
const n1 = await Note.save({ title: 'hello' });
const noteId = n1.id;
await sleep(0.1);
// Simulate the revision service being installed now. There N1 is like an old
// note that had been created before the service existed.
Setting.setValue('revisionService.installedTime', Date.now());
// Set the interval in such a way that the note is considered an old one.
Setting.setValue('revisionService.oldNoteInterval', 50);
// A revision is created the first time a note is overwritten with new content, and
// if this note doesn't already have an existing revision.

View File

@ -197,8 +197,8 @@ class Setting extends BaseModel {
'revisionService.enabled': { section: 'revisionService', value: true, type: Setting.TYPE_BOOL, public: true, label: () => _('Enable note history') },
'revisionService.ttlDays': { section: 'revisionService', value: 90, type: Setting.TYPE_INT, public: true, minimum: 1, maximum: 365 * 2, step: 1, unitLabel: (value = null) => { return value === null ? _('days') : _('%d days', value) }, label: () => _('Keep note history for') },
'revisionService.installedTime': { section: 'revisionService', value: 0, type: Setting.TYPE_INT, public: false },
'revisionService.intervalBetweenRevisions': { section: 'revisionService', value: 1000 * 60 * 10, type: Setting.TYPE_INT, public: false },
'revisionService.oldNoteInterval': { section: 'revisionService', value: 1000 * 60 * 60 * 24 * 7, type: Setting.TYPE_INT, public: false },
'welcome.wasBuilt': { value: false, type: Setting.TYPE_BOOL, public: false },
};

View File

@ -21,12 +21,6 @@ class RevisionService extends BaseService {
// the original note is saved. The goal is to have at least one revision in case the note
// is deleted or modified as a result of a bug or user mistake.
this.isOldNotesCache_ = {};
if (!Setting.value('revisionService.installedTime')) Setting.setValue('revisionService.installedTime', Date.now());
}
installedTime() {
return Setting.value('revisionService.installedTime');
}
static instance() {
@ -35,12 +29,16 @@ class RevisionService extends BaseService {
return this.instance_;
}
oldNoteCutOffDate_() {
return Date.now() - Setting.value('revisionService.oldNoteInterval');
}
async isOldNote(noteId) {
if (noteId in this.isOldNotesCache_) return this.isOldNotesCache_[noteId];
const r = await Note.noteIsOlderThan(noteId, this.installedTime());
this.isOldNotesCache_[noteId] = r;
return r;
const isOld = await Note.noteIsOlderThan(noteId, this.oldNoteCutOffDate_());
this.isOldNotesCache_[noteId] = isOld;
return isOld;
}
noteMetadata_(note) {
@ -138,7 +136,7 @@ class RevisionService extends BaseService {
const oldNote = change.before_change_item ? JSON.parse(change.before_change_item) : null;
if (note) {
if (oldNote && oldNote.updated_time < this.installedTime()) {
if (oldNote && oldNote.updated_time < this.oldNoteCutOffDate_()) {
// This is where we save the original version of this old note
await this.createNoteRevision_(oldNote);
}