You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-18 23:07:45 +02:00
All: Fix integration test harness issues. (#2723)
This commit is contained in:
@ -21,6 +21,7 @@ class ResourceFetcher extends BaseService {
|
||||
this.maxDownloads_ = 3;
|
||||
this.addingResources_ = false;
|
||||
this.eventEmitter_ = new EventEmitter();
|
||||
this.autoAddResourcesCalls_ = [];
|
||||
}
|
||||
|
||||
static instance() {
|
||||
@ -197,7 +198,12 @@ class ResourceFetcher extends BaseService {
|
||||
async waitForAllFinished() {
|
||||
return new Promise((resolve) => {
|
||||
const iid = setInterval(() => {
|
||||
if (!this.updateReportIID_ && !this.scheduleQueueProcessIID_ && !this.addingResources_ && !this.queue_.length && !Object.getOwnPropertyNames(this.fetchingItems_).length) {
|
||||
if (!this.updateReportIID_ &&
|
||||
!this.scheduleQueueProcessIID_ &&
|
||||
!this.queue_.length &&
|
||||
!this.autoAddResourcesCalls_.length &&
|
||||
!Object.getOwnPropertyNames(this.fetchingItems_).length) {
|
||||
|
||||
clearInterval(iid);
|
||||
resolve();
|
||||
}
|
||||
@ -206,25 +212,31 @@ class ResourceFetcher extends BaseService {
|
||||
}
|
||||
|
||||
async autoAddResources(limit = null) {
|
||||
if (limit === null) limit = 10;
|
||||
this.autoAddResourcesCalls_.push(true);
|
||||
try {
|
||||
if (limit === null) limit = 10;
|
||||
|
||||
if (this.addingResources_) return;
|
||||
this.addingResources_ = true;
|
||||
if (this.addingResources_) return;
|
||||
this.addingResources_ = true;
|
||||
|
||||
this.logger().info(`ResourceFetcher: Auto-add resources: Mode: ${Setting.value('sync.resourceDownloadMode')}`);
|
||||
this.logger().info(`ResourceFetcher: Auto-add resources: Mode: ${Setting.value('sync.resourceDownloadMode')}`);
|
||||
|
||||
let count = 0;
|
||||
const resources = await Resource.needToBeFetched(Setting.value('sync.resourceDownloadMode'), limit);
|
||||
for (let i = 0; i < resources.length; i++) {
|
||||
const added = this.queueDownload_(resources[i].id);
|
||||
if (added) count++;
|
||||
let count = 0;
|
||||
const resources = await Resource.needToBeFetched(Setting.value('sync.resourceDownloadMode'), limit);
|
||||
for (let i = 0; i < resources.length; i++) {
|
||||
const added = this.queueDownload_(resources[i].id);
|
||||
if (added) count++;
|
||||
}
|
||||
|
||||
this.logger().info(`ResourceFetcher: Auto-added resources: ${count}`);
|
||||
|
||||
const errorCount = await Resource.downloadStatusCounts(Resource.FETCH_STATUS_ERROR);
|
||||
if (errorCount) this.dispatch({ type: 'SYNC_HAS_DISABLED_SYNC_ITEMS' });
|
||||
|
||||
} finally {
|
||||
this.addingResources_ = false;
|
||||
this.autoAddResourcesCalls_.pop();
|
||||
}
|
||||
|
||||
this.logger().info(`ResourceFetcher: Auto-added resources: ${count}`);
|
||||
this.addingResources_ = false;
|
||||
|
||||
const errorCount = await Resource.downloadStatusCounts(Resource.FETCH_STATUS_ERROR);
|
||||
if (errorCount) this.dispatch({ type: 'SYNC_HAS_DISABLED_SYNC_ITEMS' });
|
||||
}
|
||||
|
||||
async start() {
|
||||
@ -244,6 +256,15 @@ class ResourceFetcher extends BaseService {
|
||||
}, 100);
|
||||
}
|
||||
|
||||
scheduleAutoAddResources() {
|
||||
if (this.scheduleAutoAddResourcesIID_) return;
|
||||
|
||||
this.scheduleAutoAddResourcesIID_ = setTimeout(() => {
|
||||
this.scheduleAutoAddResourcesIID_ = null;
|
||||
ResourceFetcher.instance().autoAddResources();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
async fetchAll() {
|
||||
await Resource.resetStartedFetchStatus();
|
||||
this.autoAddResources(null);
|
||||
@ -255,10 +276,13 @@ class ResourceFetcher extends BaseService {
|
||||
clearTimeout(this.scheduleQueueProcessIID_);
|
||||
this.scheduleQueueProcessIID_ = null;
|
||||
}
|
||||
if (this.scheduleAutoAddResourcesIID_) {
|
||||
clearTimeout(this.scheduleAutoAddResourcesIID_);
|
||||
this.scheduleAutoAddResourcesIID_ = null;
|
||||
}
|
||||
await this.waitForAllFinished();
|
||||
this.eventEmitter_ = null;
|
||||
ResourceFetcher.instance_ = null;
|
||||
|
||||
return await this.waitForAllFinished();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,20 @@ const ItemChangeUtils = require('lib/services/ItemChangeUtils');
|
||||
const { sprintf } = require('sprintf-js');
|
||||
|
||||
class ResourceService extends BaseService {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.maintenanceCalls_ = [];
|
||||
this.maintenanceTimer1_ = null;
|
||||
this.maintenanceTimer2_ = null;
|
||||
}
|
||||
|
||||
static instance() {
|
||||
if (this.instance_) return this.instance_;
|
||||
this.instance_ = new ResourceService();
|
||||
return this.instance_;
|
||||
}
|
||||
|
||||
async indexNoteResources() {
|
||||
this.logger().info('ResourceService::indexNoteResources: Start');
|
||||
|
||||
@ -131,24 +145,49 @@ class ResourceService extends BaseService {
|
||||
}
|
||||
|
||||
async maintenance() {
|
||||
await this.indexNoteResources();
|
||||
await this.deleteOrphanResources();
|
||||
this.maintenanceCalls_.push(true);
|
||||
try {
|
||||
await this.indexNoteResources();
|
||||
await this.deleteOrphanResources();
|
||||
} finally {
|
||||
this.maintenanceCalls_.pop();
|
||||
}
|
||||
}
|
||||
|
||||
static runInBackground() {
|
||||
if (this.isRunningInBackground_) return;
|
||||
|
||||
this.isRunningInBackground_ = true;
|
||||
const service = new ResourceService();
|
||||
const service = this.instance();
|
||||
|
||||
setTimeout(() => {
|
||||
service.maintenanceTimer1_ = setTimeout(() => {
|
||||
service.maintenance();
|
||||
}, 1000 * 30);
|
||||
|
||||
shim.setInterval(() => {
|
||||
service.maintenanceTimer2_ = shim.setInterval(() => {
|
||||
service.maintenance();
|
||||
}, 1000 * 60 * 60 * 4);
|
||||
}
|
||||
|
||||
async cancelTimers() {
|
||||
if (this.maintenanceTimer1_) {
|
||||
clearTimeout(this.maintenanceTimer1);
|
||||
this.maintenanceTimer1_ = null;
|
||||
}
|
||||
if (this.maintenanceTimer2_) {
|
||||
shim.clearInterval(this.maintenanceTimer2);
|
||||
this.maintenanceTimer2_ = null;
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
const iid = setInterval(() => {
|
||||
if (!this.maintenanceCalls_.length) {
|
||||
clearInterval(iid);
|
||||
resolve();
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ResourceService;
|
||||
|
@ -19,6 +19,10 @@ 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_ = {};
|
||||
|
||||
this.maintenanceCalls_ = [];
|
||||
this.maintenanceTimer1_ = null;
|
||||
this.maintenanceTimer2_ = null;
|
||||
}
|
||||
|
||||
static instance() {
|
||||
@ -235,22 +239,27 @@ class RevisionService extends BaseService {
|
||||
}
|
||||
|
||||
async maintenance() {
|
||||
const startTime = Date.now();
|
||||
this.logger().info('RevisionService::maintenance: Starting...');
|
||||
this.maintenanceCalls_.push(true);
|
||||
try {
|
||||
const startTime = Date.now();
|
||||
this.logger().info('RevisionService::maintenance: Starting...');
|
||||
|
||||
if (!Setting.value('revisionService.enabled')) {
|
||||
this.logger().info('RevisionService::maintenance: Service is disabled');
|
||||
// We do as if we had processed all the latest changes so that they can be cleaned up
|
||||
// later on by ItemChangeUtils.deleteProcessedChanges().
|
||||
Setting.setValue('revisionService.lastProcessedChangeId', await ItemChange.lastChangeId());
|
||||
await this.deleteOldRevisions(Setting.value('revisionService.ttlDays') * 24 * 60 * 60 * 1000);
|
||||
} else {
|
||||
this.logger().info('RevisionService::maintenance: Service is enabled');
|
||||
await this.collectRevisions();
|
||||
await this.deleteOldRevisions(Setting.value('revisionService.ttlDays') * 24 * 60 * 60 * 1000);
|
||||
if (!Setting.value('revisionService.enabled')) {
|
||||
this.logger().info('RevisionService::maintenance: Service is disabled');
|
||||
// We do as if we had processed all the latest changes so that they can be cleaned up
|
||||
// later on by ItemChangeUtils.deleteProcessedChanges().
|
||||
Setting.setValue('revisionService.lastProcessedChangeId', await ItemChange.lastChangeId());
|
||||
await this.deleteOldRevisions(Setting.value('revisionService.ttlDays') * 24 * 60 * 60 * 1000);
|
||||
} else {
|
||||
this.logger().info('RevisionService::maintenance: Service is enabled');
|
||||
await this.collectRevisions();
|
||||
await this.deleteOldRevisions(Setting.value('revisionService.ttlDays') * 24 * 60 * 60 * 1000);
|
||||
|
||||
this.logger().info(`RevisionService::maintenance: Done in ${Date.now() - startTime}ms`);
|
||||
}
|
||||
} finally {
|
||||
this.maintenanceCalls_.pop();
|
||||
}
|
||||
|
||||
this.logger().info(`RevisionService::maintenance: Done in ${Date.now() - startTime}ms`);
|
||||
}
|
||||
|
||||
runInBackground(collectRevisionInterval = null) {
|
||||
@ -261,14 +270,34 @@ class RevisionService extends BaseService {
|
||||
|
||||
this.logger().info(`RevisionService::runInBackground: Starting background service with revision collection interval ${collectRevisionInterval}`);
|
||||
|
||||
setTimeout(() => {
|
||||
this.maintenanceTimer1_ = setTimeout(() => {
|
||||
this.maintenance();
|
||||
}, 1000 * 4);
|
||||
|
||||
shim.setInterval(() => {
|
||||
this.maintenanceTImer2_ = shim.setInterval(() => {
|
||||
this.maintenance();
|
||||
}, collectRevisionInterval);
|
||||
}
|
||||
|
||||
async cancelTimers() {
|
||||
if (this.maintenanceTimer1_) {
|
||||
clearTimeout(this.maintenanceTimer1);
|
||||
this.maintenanceTimer1_ = null;
|
||||
}
|
||||
if (this.maintenanceTimer2_) {
|
||||
shim.clearInterval(this.maintenanceTimer2);
|
||||
this.maintenanceTimer2_ = null;
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
const iid = setInterval(() => {
|
||||
if (!this.maintenanceCalls_.length) {
|
||||
clearInterval(iid);
|
||||
resolve();
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RevisionService;
|
||||
|
@ -424,6 +424,7 @@ class SearchEngine {
|
||||
const iid = setInterval(() => {
|
||||
if (!this.syncCalls_.length) {
|
||||
clearInterval(iid);
|
||||
this.instance_ = null;
|
||||
resolve();
|
||||
}
|
||||
}, 100);
|
||||
|
Reference in New Issue
Block a user