mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
All: Optimised resource download queue by exiting early if resources are already downloaded
This commit is contained in:
parent
0200aa92de
commit
349cade946
@ -32,6 +32,11 @@ class Resource extends BaseItem {
|
||||
return imageMimeTypes.indexOf(type.toLowerCase()) >= 0;
|
||||
}
|
||||
|
||||
static fetchStatuses(resourceIds) {
|
||||
if (!resourceIds.length) return [];
|
||||
return this.db().selectAll('SELECT resource_id, fetch_status FROM resource_local_states WHERE resource_id IN ("' + resourceIds.join('","') + '")');
|
||||
}
|
||||
|
||||
static needToBeFetched(resourceDownloadMode = null, limit = null) {
|
||||
let sql = ['SELECT * FROM resources WHERE encryption_applied = 0 AND id IN (SELECT resource_id FROM resource_local_states WHERE fetch_status = ?)'];
|
||||
if (resourceDownloadMode !== 'always') {
|
||||
|
@ -75,11 +75,19 @@ class ResourceFetcher extends BaseService {
|
||||
async markForDownload(resourceIds) {
|
||||
if (!Array.isArray(resourceIds)) resourceIds = [resourceIds];
|
||||
|
||||
for (const id of resourceIds) {
|
||||
const fetchStatuses = await Resource.fetchStatuses(resourceIds);
|
||||
|
||||
const idsToKeep = [];
|
||||
for (const status of fetchStatuses) {
|
||||
if (status.fetch_status !== Resource.FETCH_STATUS_IDLE) continue;
|
||||
idsToKeep.push(status.resource_id);
|
||||
}
|
||||
|
||||
for (const id of idsToKeep) {
|
||||
await Resource.markForDownload(id);
|
||||
}
|
||||
|
||||
for (const id of resourceIds) {
|
||||
for (const id of idsToKeep) {
|
||||
this.queueDownload_(id, 'high');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user