Skip to content

Commit 0e6000f

Browse files
committed
Fix: Optimized index loading and folder navigation
1 parent 153902c commit 0e6000f

12 files changed

+191
-88
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1818
- S3 connection does not work correctly in Windows [`9352e3a`](https://github.com/ollm/OpenComic/commit/9352e3a388a4a1aea2f45155d72d057172808d56)
1919
- Don't show drag menu if the event comes from the app [`383f9fe`](https://github.com/ollm/OpenComic/commit/383f9fe30d535260e6f6091242289d99ac4d755b)
2020
- PDF zoom not work if device pixel ratio is upper 1 [`d318cfc`](https://github.com/ollm/OpenComic/commit/d318cfc071b5e8d919b4c8acef89b85e8ef40cc8)
21+
- Optimized index loading and folder navigation
2122

2223

2324
## [v1.2.0](https://github.com/ollm/OpenComic/releases/tag/v1.2.0) (29-03-2024)

scripts/app.js

+31
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,36 @@ function copy(toCopy)
235235
}
236236
}
237237

238+
var throttles = {};
239+
var debounces = {};
240+
241+
async function setThrottle(key, callback, debounce = 300, throttle = 3000)
242+
{
243+
clearTimeout(debounces[key]);
244+
245+
debounces[key] = setTimeout(function(){
246+
247+
clearTimeout(throttles[key]);
248+
throttles[key] = false;
249+
250+
callback(true);
251+
252+
}, debounce);
253+
254+
if(throttles[key] === undefined || throttles[key] === false)
255+
{
256+
throttles[key] = setTimeout(function(){
257+
258+
clearTimeout(debounces[key]);
259+
throttles[key] = false;
260+
261+
callback();
262+
263+
}, throttle);
264+
}
265+
}
266+
267+
238268
function time()
239269
{
240270
return Math.floor(Date.now() / 1000);
@@ -279,4 +309,5 @@ module.exports = {
279309
time: time,
280310
sleep: sleep,
281311
setImmediate: setImmediate,
312+
setThrottle: setThrottle,
282313
};

scripts/cache.js

+21
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ if(!fs.existsSync(cacheFolder)) fs.mkdirSync(cacheFolder);
2727
cacheFolder = p.join(cacheFolder, 'cache');
2828
if(!fs.existsSync(cacheFolder)) fs.mkdirSync(cacheFolder);
2929

30+
var imagesWithoutSaving = 0;
31+
3032
function processTheImageQueue()
3133
{
3234
let img = queuedImages[0];
@@ -55,12 +57,21 @@ function processTheImageQueue()
5557

5658
if(queuedImages.length > 0)
5759
{
60+
imagesWithoutSaving++;
61+
5862
process.nextTick(function() {
5963
processTheImageQueue();
6064
});
65+
66+
if(imagesWithoutSaving > 50)
67+
{
68+
imagesWithoutSaving = 0;
69+
storage.setThrottle('cache', data);
70+
}
6171
}
6272
else
6373
{
74+
imagesWithoutSaving = 0;
6475
processingTheImageQueue = false;
6576

6677
storage.setThrottle('cache', data);
@@ -74,12 +85,21 @@ function processTheImageQueue()
7485

7586
if(queuedImages.length > 0)
7687
{
88+
imagesWithoutSaving++;
89+
7790
process.nextTick(function() {
7891
processTheImageQueue();
7992
});
93+
94+
if(imagesWithoutSaving > 50)
95+
{
96+
imagesWithoutSaving = 0;
97+
storage.setThrottle('cache', data);
98+
}
8099
}
81100
else
82101
{
102+
imagesWithoutSaving = 0;
83103
processingTheImageQueue = false;
84104

85105
storage.setThrottle('cache', data);
@@ -135,6 +155,7 @@ function resumeQueue()
135155
function cleanQueue()
136156
{
137157
queuedImages.splice(1, queuedImages.length - 1);
158+
if(data !== false) storage.setThrottle('cache', data);
138159
}
139160

140161
var data = false;

0 commit comments

Comments
 (0)