mirror of
https://github.com/laurent22/joplin.git
synced 2024-11-27 08:21:03 +02:00
Updated the way item changes are recorded so that info can be used by more services (including search engine)
This commit is contained in:
parent
3b6131f1ca
commit
cb16a10121
@ -8,6 +8,7 @@ const Note = require('lib/models/Note.js');
|
||||
const Tag = require('lib/models/Tag.js');
|
||||
const NoteTag = require('lib/models/NoteTag.js');
|
||||
const Resource = require('lib/models/Resource.js');
|
||||
const ItemChange = require('lib/models/ItemChange.js');
|
||||
const NoteResource = require('lib/models/NoteResource.js');
|
||||
const ResourceService = require('lib/services/ResourceService.js');
|
||||
const fs = require('fs-extra');
|
||||
@ -124,4 +125,25 @@ describe('services_ResourceService', function() {
|
||||
expect(!!(await Resource.load(resource1.id))).toBe(true);
|
||||
}));
|
||||
|
||||
it('should not process twice the same change', asyncTest(async () => {
|
||||
const service = new ResourceService();
|
||||
|
||||
let folder1 = await Folder.save({ title: "folder1" });
|
||||
let note1 = await Note.save({ title: 'ma note', parent_id: folder1.id });
|
||||
note1 = await shim.attachFileToNote(note1, __dirname + '/../tests/support/photo.jpg');
|
||||
let resource1 = (await Resource.all())[0];
|
||||
|
||||
await service.indexNoteResources();
|
||||
|
||||
const before = (await NoteResource.all())[0];
|
||||
|
||||
await time.sleep(0.1);
|
||||
|
||||
await service.indexNoteResources();
|
||||
|
||||
const after = (await NoteResource.all())[0];
|
||||
|
||||
expect(before.last_seen_time).toBe(after.last_seen_time);
|
||||
}));
|
||||
|
||||
});
|
@ -157,6 +157,8 @@ class Setting extends BaseModel {
|
||||
'net.ignoreTlsErrors': { value: false, type: Setting.TYPE_BOOL, show: (settings) => { return [SyncTargetRegistry.nameToId('nextcloud'), SyncTargetRegistry.nameToId('webdav')].indexOf(settings['sync.target']) >= 0 }, public: true, appTypes: ['desktop', 'cli'], label: () => _('Ignore TLS certificate errors') },
|
||||
|
||||
'api.token': { value: null, type: Setting.TYPE_STRING, public: false },
|
||||
|
||||
'resourceService.lastProcessedChangeId': { value: 0, type: Setting.TYPE_INT, public: false },
|
||||
};
|
||||
|
||||
return this.metadata_;
|
||||
@ -459,27 +461,6 @@ class Setting extends BaseModel {
|
||||
return output;
|
||||
}
|
||||
|
||||
// Currently only supports objects with properties one level deep
|
||||
// static object(key) {
|
||||
// let output = {};
|
||||
// let keys = this.keys();
|
||||
// for (let i = 0; i < keys.length; i++) {
|
||||
// let k = keys[i].split('.');
|
||||
// if (k[0] == key) {
|
||||
// output[k[1]] = this.value(keys[i]);
|
||||
// }
|
||||
// }
|
||||
// return output;
|
||||
// }
|
||||
|
||||
// Currently only supports objects with properties one level deep
|
||||
// static setObject(key, object) {
|
||||
// for (let n in object) {
|
||||
// if (!object.hasOwnProperty(n)) continue;
|
||||
// this.setValue(key + '.' + n, object[n]);
|
||||
// }
|
||||
// }
|
||||
|
||||
static async saveAll() {
|
||||
if (!this.saveTimeoutId_) return Promise.resolve();
|
||||
|
||||
|
@ -4,6 +4,7 @@ const Note = require('lib/models/Note');
|
||||
const Resource = require('lib/models/Resource');
|
||||
const BaseModel = require('lib/BaseModel');
|
||||
const BaseService = require('lib/services/BaseService');
|
||||
const Setting = require('lib/models/Setting');
|
||||
const { shim } = require('lib/shim');
|
||||
|
||||
class ResourceService extends BaseService {
|
||||
@ -11,10 +12,6 @@ class ResourceService extends BaseService {
|
||||
async indexNoteResources() {
|
||||
this.logger().info('ResourceService::indexNoteResources: Start');
|
||||
|
||||
let lastId = 0;
|
||||
|
||||
const processedChangeIds = [];
|
||||
|
||||
await ItemChange.waitForAllSaved();
|
||||
|
||||
while (true) {
|
||||
@ -25,7 +22,7 @@ class ResourceService extends BaseService {
|
||||
AND id > ?
|
||||
ORDER BY id ASC
|
||||
LIMIT 100
|
||||
`, [BaseModel.TYPE_NOTE, lastId]);
|
||||
`, [BaseModel.TYPE_NOTE, Setting.value('resourceService.lastProcessedChangeId')]);
|
||||
|
||||
if (!changes.length) break;
|
||||
|
||||
@ -61,15 +58,11 @@ class ResourceService extends BaseService {
|
||||
throw new Error('Invalid change type: ' + change.type);
|
||||
}
|
||||
|
||||
lastId = change.id;
|
||||
|
||||
processedChangeIds.push(change.id);
|
||||
Setting.setValue('resourceService.lastProcessedChangeId', change.id);
|
||||
}
|
||||
}
|
||||
|
||||
if (lastId) {
|
||||
await ItemChange.db().exec('DELETE FROM item_changes WHERE id <= ?', [lastId]);
|
||||
}
|
||||
await Setting.saveAll();
|
||||
|
||||
await NoteResource.addOrphanedResources();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user