mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-27 10:32:58 +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:
parent
a4db1bc671
commit
78372c9bac
@ -177,15 +177,14 @@ describe('services_Revision', function() {
|
|||||||
expect(revNote3.title).toBe('hello John');
|
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 n1 = await Note.save({ title: 'hello' });
|
||||||
const noteId = n1.id;
|
const noteId = n1.id;
|
||||||
|
|
||||||
await sleep(0.1);
|
await sleep(0.1);
|
||||||
|
|
||||||
// Simulate the revision service being installed now. There N1 is like an old
|
// Set the interval in such a way that the note is considered an old one.
|
||||||
// note that had been created before the service existed.
|
Setting.setValue('revisionService.oldNoteInterval', 50);
|
||||||
Setting.setValue('revisionService.installedTime', Date.now());
|
|
||||||
|
|
||||||
// A revision is created the first time a note is overwritten with new content, and
|
// 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.
|
// if this note doesn't already have an existing revision.
|
||||||
|
@ -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.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.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.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 },
|
'welcome.wasBuilt': { value: false, type: Setting.TYPE_BOOL, public: false },
|
||||||
};
|
};
|
||||||
|
@ -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
|
// 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.
|
// is deleted or modified as a result of a bug or user mistake.
|
||||||
this.isOldNotesCache_ = {};
|
this.isOldNotesCache_ = {};
|
||||||
|
|
||||||
if (!Setting.value('revisionService.installedTime')) Setting.setValue('revisionService.installedTime', Date.now());
|
|
||||||
}
|
|
||||||
|
|
||||||
installedTime() {
|
|
||||||
return Setting.value('revisionService.installedTime');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static instance() {
|
static instance() {
|
||||||
@ -35,12 +29,16 @@ class RevisionService extends BaseService {
|
|||||||
return this.instance_;
|
return this.instance_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
oldNoteCutOffDate_() {
|
||||||
|
return Date.now() - Setting.value('revisionService.oldNoteInterval');
|
||||||
|
}
|
||||||
|
|
||||||
async isOldNote(noteId) {
|
async isOldNote(noteId) {
|
||||||
if (noteId in this.isOldNotesCache_) return this.isOldNotesCache_[noteId];
|
if (noteId in this.isOldNotesCache_) return this.isOldNotesCache_[noteId];
|
||||||
|
|
||||||
const r = await Note.noteIsOlderThan(noteId, this.installedTime());
|
const isOld = await Note.noteIsOlderThan(noteId, this.oldNoteCutOffDate_());
|
||||||
this.isOldNotesCache_[noteId] = r;
|
this.isOldNotesCache_[noteId] = isOld;
|
||||||
return r;
|
return isOld;
|
||||||
}
|
}
|
||||||
|
|
||||||
noteMetadata_(note) {
|
noteMetadata_(note) {
|
||||||
@ -138,7 +136,7 @@ class RevisionService extends BaseService {
|
|||||||
const oldNote = change.before_change_item ? JSON.parse(change.before_change_item) : null;
|
const oldNote = change.before_change_item ? JSON.parse(change.before_change_item) : null;
|
||||||
|
|
||||||
if (note) {
|
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
|
// This is where we save the original version of this old note
|
||||||
await this.createNoteRevision_(oldNote);
|
await this.createNoteRevision_(oldNote);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user