1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-12 22:57:38 +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:
Laurent Cozic
2018-12-10 01:39:31 +01:00
parent 3b6131f1ca
commit cb16a10121
3 changed files with 28 additions and 32 deletions

View File

@ -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();