Add chunksize to thumbnail requests.

This commit is contained in:
Lars Jung 2016-08-11 19:50:28 +02:00
parent 6c52ae659f
commit e10fe49cc0
2 changed files with 16 additions and 8 deletions

View File

@ -352,6 +352,7 @@
- delay: number, delay in milliseconds after "dom-ready" before thumb-requesting starts
- size: number, size in pixel of the generated thumbnails
- exif: boolean, use included EXIF thumbs if possible
- chunksize: int, number of thumbs per request
*/
"thumbnails": {
"enabled": true,
@ -360,7 +361,8 @@
"doc": ["x-pdf", "x-ps"],
"delay": 1,
"size": 240,
"exif": false
"exif": false,
"chunksize": 20
},
/*

View File

@ -10,7 +10,8 @@ const settings = Object.assign({
doc: ['x-pdf', 'x-ps'],
delay: 1,
size: 100,
exif: false
exif: false,
chunksize: 20
}, allsettings.thumbnails);
const landscapeRatio = 4 / 3;
@ -71,7 +72,7 @@ const requestQueue = queue => {
};
});
server.request({
return server.request({
action: 'get',
thumbs
}).then(json => {
@ -81,14 +82,19 @@ const requestQueue = queue => {
});
};
const breakAndRequestQueue = queue => {
const len = queue.length;
const chunksize = settings.chunksize;
let p = Promise.resolve();
for (let i = 0; i < len; i += chunksize) {
p = p.then(() => requestQueue(queue.slice(i, i + chunksize)));
}
};
const handleItems = items => {
const queue = [];
each(items, item => queueItem(queue, item));
if (queue.length) {
requestQueue(queue);
}
breakAndRequestQueue(queue);
};
const onViewChanged = added => {