Skip to content

Commit

Permalink
Fix: Optimized index loading and folder navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
ollm committed May 5, 2024
1 parent 153902c commit 0e6000f
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 88 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- S3 connection does not work correctly in Windows [`9352e3a`](https://github.com/ollm/OpenComic/commit/9352e3a388a4a1aea2f45155d72d057172808d56)
- Don't show drag menu if the event comes from the app [`383f9fe`](https://github.com/ollm/OpenComic/commit/383f9fe30d535260e6f6091242289d99ac4d755b)
- PDF zoom not work if device pixel ratio is upper 1 [`d318cfc`](https://github.com/ollm/OpenComic/commit/d318cfc071b5e8d919b4c8acef89b85e8ef40cc8)
- Optimized index loading and folder navigation


## [v1.2.0](https://github.com/ollm/OpenComic/releases/tag/v1.2.0) (29-03-2024)
Expand Down
31 changes: 31 additions & 0 deletions scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,36 @@ function copy(toCopy)
}
}

var throttles = {};
var debounces = {};

async function setThrottle(key, callback, debounce = 300, throttle = 3000)
{
clearTimeout(debounces[key]);

debounces[key] = setTimeout(function(){

clearTimeout(throttles[key]);
throttles[key] = false;

callback(true);

}, debounce);

if(throttles[key] === undefined || throttles[key] === false)
{
throttles[key] = setTimeout(function(){

clearTimeout(debounces[key]);
throttles[key] = false;

callback();

}, throttle);
}
}


function time()
{
return Math.floor(Date.now() / 1000);
Expand Down Expand Up @@ -279,4 +309,5 @@ module.exports = {
time: time,
sleep: sleep,
setImmediate: setImmediate,
setThrottle: setThrottle,
};
21 changes: 21 additions & 0 deletions scripts/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ if(!fs.existsSync(cacheFolder)) fs.mkdirSync(cacheFolder);
cacheFolder = p.join(cacheFolder, 'cache');
if(!fs.existsSync(cacheFolder)) fs.mkdirSync(cacheFolder);

var imagesWithoutSaving = 0;

function processTheImageQueue()
{
let img = queuedImages[0];
Expand Down Expand Up @@ -55,12 +57,21 @@ function processTheImageQueue()

if(queuedImages.length > 0)
{
imagesWithoutSaving++;

process.nextTick(function() {
processTheImageQueue();
});

if(imagesWithoutSaving > 50)
{
imagesWithoutSaving = 0;
storage.setThrottle('cache', data);
}
}
else
{
imagesWithoutSaving = 0;
processingTheImageQueue = false;

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

if(queuedImages.length > 0)
{
imagesWithoutSaving++;

process.nextTick(function() {
processTheImageQueue();
});

if(imagesWithoutSaving > 50)
{
imagesWithoutSaving = 0;
storage.setThrottle('cache', data);
}
}
else
{
imagesWithoutSaving = 0;
processingTheImageQueue = false;

storage.setThrottle('cache', data);
Expand Down Expand Up @@ -135,6 +155,7 @@ function resumeQueue()
function cleanQueue()
{
queuedImages.splice(1, queuedImages.length - 1);
if(data !== false) storage.setThrottle('cache', data);
}

var data = false;
Expand Down
Loading

0 comments on commit 0e6000f

Please sign in to comment.