Skip to content

Commit a4874a6

Browse files
committed
New: Use single thread in HDD extractions
1 parent 6968de8 commit a4874a6

7 files changed

Lines changed: 218 additions & 35 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1515
- Support Discord Rich Presence [`a19f9eb`](https://github.com/ollm/OpenComic/commit/a19f9eb6dd99350037b7c77f14e706223256af4c)
1616
- Get Calibre `series` and `series_index` metadata in PDF and ePub [`da739de`](https://github.com/ollm/OpenComic/commit/da739ded8ff1cdbc2b5da39662e85e725cd71545)
1717
- Increase and decrease horizontal margin shortcuts [`0bae05f`](https://github.com/ollm/OpenComic/commit/0bae05f210018120b56210797cd5850e13254aa9)
18+
- Use single thread in HDD extractions
1819

1920
##### 🐛 Bug Fixes
2021

‎package-lock.json‎

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
"short-windows-path": "^1.0.3",
113113
"shosho": "^1.4.3",
114114
"ssh2-sftp-client": "v12.0.1",
115+
"systeminformation": "^5.27.6",
115116
"webdav": "^5.8.0"
116117
},
117118
"devDependencies": {

‎scripts/file-manager.js‎

Lines changed: 64 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const requestFileAccess = require(p.join(appDir, 'scripts/file-manager/request-file-access.js'))
2-
filePassword = require(p.join(appDir, 'scripts/file-manager/file-password.js'));
2+
filePassword = require(p.join(appDir, 'scripts/file-manager/file-password.js')),
3+
diskType = require(p.join(appDir, 'scripts/file-manager/disk-type.js'));
34

45
var un7z = false, bin7z = false, fastXmlParser = false, Minimatch = false;
56

@@ -1869,6 +1870,17 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
18691870

18701871
}
18711872

1873+
this.getOptimalThreads = function() {
1874+
1875+
const disk = diskType.check(this.realPath);
1876+
1877+
if(disk.hdd)
1878+
return {readKey: 'readUsingThreadsHDD', extractKey: 'extractUsingThreadsHDD', read: 0.01, extract: 0.01};
1879+
else
1880+
return {readKey: 'readUsingThreads', extractKey: 'extractUsingThreads', read: 1, extract: 1};
1881+
1882+
}
1883+
18721884
// 7z
18731885
this._7z = false;
18741886

@@ -1893,51 +1905,67 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
18931905

18941906
this.read7z = async function(callback = false) {
18951907

1896-
const files = [];
1897-
18981908
const self = this;
1909+
const optimalThreads = this.getOptimalThreads();
18991910

1900-
const _7z = await this.open7z();
1901-
let readSome = false;
1911+
return threads.job(optimalThreads.readKey, {useThreads: optimalThreads.read}, async function() {
19021912

1903-
return new Promise(function(resolve, reject) {
1913+
return new Promise(async function(resolve, reject) {
19041914

1905-
_7z.on('data', function(data) {
1915+
let readSome = false;
1916+
let endEvent = false;
19061917

1907-
if(data.file)
1908-
{
1909-
if(/^D/.test(data.attributes) && !data.size) // Ignore directories
1910-
return;
1918+
const files = [];
1919+
const _7z = await self.open7z();
19111920

1912-
const originalName = self.removeTmp(p.normalize(data.file));
1913-
const name = self.fixUnsupportedCharsInWindows(originalName);
1914-
const same = originalName === name ? true : false;
1921+
_7z.on('data', function(data) {
19151922

1916-
files.push({name: name, fixedName: (!same ? name : ''), originalName: (!same ? originalName : ''), path: p.join(self.path, name), fileSize: data.size});
1917-
self.setFileStatus(name, {extracted: false});
1923+
if(data.file)
1924+
{
1925+
if(/^D/.test(data.attributes) && !data.size) // Ignore directories
1926+
return;
19181927

1919-
readSome = true;
1920-
}
1928+
const originalName = self.removeTmp(p.normalize(data.file));
1929+
const name = self.fixUnsupportedCharsInWindows(originalName);
1930+
const same = originalName === name ? true : false;
19211931

1922-
}).on('end', function(data) {
1932+
files.push({name: name, fixedName: (!same ? name : ''), originalName: (!same ? originalName : ''), path: p.join(self.path, name), fileSize: data.size});
1933+
self.setFileStatus(name, {extracted: false});
19231934

1924-
self.files = self.filesToMultidimension(files);
1925-
resolve(self.files);
1935+
readSome = true;
1936+
}
19261937

1927-
}).on('error', function(error){
1938+
}).on('end', function(data) {
19281939

1929-
if(readSome)
1930-
{
1931-
/*self.files = self.filesToMultidimension(files);
1932-
resolve(self.files);*/
1940+
endEvent = true;
19331941

1934-
//self.saveErrorToCache(error);
1935-
dom.compressedError(error, false, sha1(self.path));
1936-
}
1937-
else
1938-
{
1939-
reject(error);
1940-
}
1942+
self.files = self.filesToMultidimension(files);
1943+
resolve(self.files);
1944+
1945+
}).on('error', function(error){
1946+
1947+
if(readSome)
1948+
{
1949+
//self.saveErrorToCache(error);
1950+
dom.compressedError(error, false, sha1(self.path));
1951+
1952+
// Just in case the 'end' event is not called
1953+
setTimeout(function() {
1954+
1955+
if(endEvent)
1956+
return;
1957+
1958+
self.files = self.filesToMultidimension(files);
1959+
resolve(self.files);
1960+
1961+
}, 5000);
1962+
}
1963+
else
1964+
{
1965+
reject(error);
1966+
}
1967+
1968+
});
19411969

19421970
});
19431971

@@ -1948,6 +1976,7 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
19481976
this.extract7z = async function() {
19491977

19501978
const self = this;
1979+
const optimalThreads = this.getOptimalThreads();
19511980

19521981
const only = [];
19531982
const extractName = {};
@@ -1979,7 +2008,7 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
19792008
let extractedSome = false;
19802009
let hasError = false;
19812010

1982-
promises.push(threads.job('extractUsingThreads', {useThreads: 1}, async function() {
2011+
promises.push(threads.job(optimalThreads.extractKey, {useThreads: optimalThreads.extract}, async function() {
19832012

19842013
return new Promise(async function(resolve, reject) {
19852014

@@ -3600,4 +3629,5 @@ module.exports = {
36003629
fileSizes: function(){return fileSizes},
36013630
requestFileAccess: requestFileAccess,
36023631
filePassword: filePassword,
3632+
diskType: diskType,
36033633
}

‎scripts/file-manager/disk-type.js‎

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
const systemInfo = require('systeminformation');
2+
3+
var runned = false;
4+
5+
async function findDisks(force = false)
6+
{
7+
if(runned && !force)
8+
return;
9+
10+
runned = true;
11+
12+
const disks = [];
13+
14+
if(process.platform == 'win32')
15+
{
16+
const diskLayout = await systemInfo.diskLayout();
17+
const fsSize = await systemInfo.fsSize();
18+
const blockDevices = await si.blockDevices();
19+
20+
/*
21+
22+
23+
24+
25+
26+
27+
*/
28+
}
29+
else
30+
{
31+
const diskLayout = await systemInfo.diskLayout();
32+
const fsSize = await systemInfo.fsSize();
33+
34+
for(const layout of diskLayout)
35+
{
36+
const regex = layout.device ? new RegExp('^'+pregQuote(layout.device), '') : false;;
37+
const mount = fsSize.find(function(size) {
38+
39+
return regex && size.fs && regex.test(size.fs) ? true : false;
40+
41+
});
42+
43+
if(mount)
44+
{
45+
disks.push({
46+
name: layout.name,
47+
mount: mount.mount,
48+
type: layout.type,
49+
hdd: /HD/iu.test(layout.type),
50+
ssd: /SSD/iu.test(layout.type),
51+
nvme: /NVMe/iu.test(layout.type),
52+
});
53+
}
54+
}
55+
}
56+
57+
disks.sort(function(a, b) {
58+
59+
if(a.mount.length === b.mount.length)
60+
return 0;
61+
62+
return a.mount.length > b.mount.length ? -1 : 1;
63+
64+
});
65+
66+
storage.set('disks', disks);
67+
getDisks(true); // Update disks cache
68+
69+
return disks;
70+
}
71+
72+
var disks = false;
73+
74+
function getDisks(force = false)
75+
{
76+
if(disks !== false && !force)
77+
return disks;
78+
79+
if(!force)
80+
findDisks();
81+
82+
disks = storage.get('disks') || [];
83+
84+
for(const disk of disks)
85+
{
86+
disk.mountRegex = new RegExp('^'+pregQuote(disk.mount), '');
87+
}
88+
89+
return disks;
90+
}
91+
92+
function check(path)
93+
{
94+
const disks = getDisks();
95+
96+
for(let i = 0, len = disks.length; i < len; i++)
97+
{
98+
const disk = disks[i];
99+
100+
if(disk.mountRegex.test(path))
101+
return disk;
102+
}
103+
104+
return {
105+
hdd: false,
106+
ssd: true,
107+
nvme: false,
108+
};
109+
}
110+
111+
module.exports = {
112+
check,
113+
getDisks,
114+
findDisks,
115+
};

‎scripts/opencomic.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ async function startApp()
381381
dragAndDrop.start();
382382
dom.search.start();
383383
tracking.start();
384+
fileManager.diskType.findDisks();
384385

385386
document.fonts.ready.then(function(){
386387

‎scripts/storage.js‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const safe = require(p.join(appDir, 'scripts/storage/safe.js'));
22

3-
const changes = 121; // Update this if readingPagesConfig is updated
3+
const changes = 122; // Update this if readingPagesConfig is updated
44

55
const readingPagesConfig = {
66
readingConfigName: '',
@@ -423,6 +423,14 @@ const storageDefault = {
423423
author: '',
424424
}
425425
},
426+
disks: [{
427+
name: '',
428+
mount: '',
429+
type: '',
430+
hdd: false,
431+
ssd: false,
432+
nvme: false,
433+
}],
426434
cache: {
427435
wildcard: {
428436
lastAccess: 0,

0 commit comments

Comments
 (0)