perf(torrents): ability to disable integrity check on torrents adding torrents #47
This option will optimize db usage performance on big databases
This commit is contained in:
parent
3743a60bec
commit
e7b035a1a8
@ -247,6 +247,18 @@ export default class ConfigPage extends Page {
|
||||
/>
|
||||
<div className='fs0-75' style={{color: 'grey'}}>* {__('Enable torrents replication from another rats clients. Dont recomended if torrent scanner works correct')}.</div>
|
||||
</div>
|
||||
<div className='column w100p'>
|
||||
<Toggle
|
||||
style={{marginTop: '10px'}}
|
||||
label={__('Check torrent files intergrity')}
|
||||
toggled={this.options.recheckFilesOnAdding}
|
||||
onToggle={(e, checked) => {
|
||||
this.options.recheckFilesOnAdding = checked
|
||||
this.forceUpdate()
|
||||
}}
|
||||
/>
|
||||
<div className='fs0-75' style={{color: 'grey'}}>* {__('Enable database torrents files intergrity check on adding each torrent. Disable this will free some cpu usage on adding operation.')}</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div style={{marginTop: 10}}>{__('Torrent network scanner settings')}:</div>
|
||||
|
@ -59,6 +59,7 @@ let config = {
|
||||
cleanupDiscLimit: 7 * 1024 * 1024 * 1024,
|
||||
spaceQuota: false,
|
||||
spaceDiskLimit: 7 * 1024 * 1024 * 1024,
|
||||
recheckFilesOnAdding: true,
|
||||
|
||||
dbPath: '',
|
||||
|
||||
|
@ -384,6 +384,42 @@ module.exports = function (send, recive, dataDirectory, version, env)
|
||||
|
||||
torrent.id = torrentsId++;
|
||||
|
||||
const recheckFiles = (callback) => {
|
||||
sphinxSingle.query('SELECT count(*) as files_count FROM files WHERE hash = ?', [torrent.hash], function(err, rows) {
|
||||
if(!rows)
|
||||
return
|
||||
|
||||
const db_files = rows[0]['files_count'];
|
||||
if(db_files !== torrent.files)
|
||||
{
|
||||
callback()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const addFilesToDatabase = () => {
|
||||
sphinxSingle.query('DELETE FROM files WHERE hash = ?', torrent.hash, function (err, result) {
|
||||
if(err)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
filesList.forEach((file) => {
|
||||
file.id = filesId++;
|
||||
file.pathIndex = file.path;
|
||||
});
|
||||
|
||||
sphinxSingle.insertValues('files', filesList, function(err, result) {
|
||||
if(!result) {
|
||||
console.error(err);
|
||||
return
|
||||
}
|
||||
if(!silent)
|
||||
send('filesReady', torrent.hash);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
sphinxSingle.query("SELECT id FROM torrents WHERE hash = ?", torrent.hash, (err, single) => {
|
||||
if(!single)
|
||||
{
|
||||
@ -392,11 +428,21 @@ module.exports = function (send, recive, dataDirectory, version, env)
|
||||
return
|
||||
}
|
||||
|
||||
// torrent already probably in db
|
||||
if(single.length > 0)
|
||||
{
|
||||
if(config.recheckFilesOnAdding)
|
||||
{
|
||||
// recheck files and if they not ok add their to database
|
||||
recheckFiles(addFilesToDatabase)
|
||||
}
|
||||
resolve()
|
||||
return
|
||||
}
|
||||
else
|
||||
{
|
||||
addFilesToDatabase()
|
||||
}
|
||||
|
||||
torrent.nameIndex = torrent.name
|
||||
|
||||
@ -423,36 +469,6 @@ module.exports = function (send, recive, dataDirectory, version, env)
|
||||
events.emit('insert', torrent)
|
||||
});
|
||||
})
|
||||
|
||||
sphinxSingle.query('SELECT count(*) as files_count FROM files WHERE hash = ?', [torrent.hash], function(err, rows) {
|
||||
if(!rows)
|
||||
return
|
||||
|
||||
const db_files = rows[0]['files_count'];
|
||||
if(db_files !== torrent.files)
|
||||
{
|
||||
sphinxSingle.query('DELETE FROM files WHERE hash = ?', torrent.hash, function (err, result) {
|
||||
if(err)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
filesList.forEach((file) => {
|
||||
file.id = filesId++;
|
||||
file.pathIndex = file.path;
|
||||
});
|
||||
|
||||
sphinxSingle.insertValues('files', filesList, function(err, result) {
|
||||
if(!result) {
|
||||
console.error(err);
|
||||
return
|
||||
}
|
||||
if(!silent)
|
||||
send('filesReady', torrent.hash);
|
||||
});
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
const removeTorrentFromDB = async (torrent) => {
|
||||
|
@ -185,6 +185,8 @@
|
||||
"calculation": "calculation",
|
||||
"removing": "removing",
|
||||
"Torrents cleaned": "Torrents cleaned",
|
||||
"or with hash": "or with hash"
|
||||
"or with hash": "or with hash",
|
||||
"Check torrent files intergrity": "Check torrent files intergrity",
|
||||
"Enable database torrents files intergrity check on adding each torrent. Disable this will free some cpu usage on adding operation.": "Enable database torrents files intergrity check on adding each torrent. Disable this will free some cpu usage on adding operation."
|
||||
}
|
||||
}
|
@ -185,6 +185,8 @@
|
||||
"calculation": "подсчитывается",
|
||||
"removing": "удаляется",
|
||||
"Torrents cleaned": "Торренты очещены",
|
||||
"or with hash": "или по хэшу"
|
||||
"or with hash": "или по хэшу",
|
||||
"Check torrent files intergrity": "Проверка целостности файлов",
|
||||
"Enable database torrents files intergrity check on adding each torrent. Disable this will free some cpu usage on adding operation.": "Включить проверку целостности файлов в базе при добавлении каждого торрента. Отключение этой опции освободит некоторорое количество ресурсов процессора при добавлении."
|
||||
}
|
||||
}
|
@ -185,6 +185,8 @@
|
||||
"calculation": "calculation",
|
||||
"removing": "removing",
|
||||
"Torrents cleaned": "Torrents cleaned",
|
||||
"or with hash": "or with hash"
|
||||
"or with hash": "or with hash",
|
||||
"Check torrent files intergrity": "Check torrent files intergrity",
|
||||
"Enable database torrents files intergrity check on adding each torrent. Disable this will free some cpu usage on adding operation.": "Enable database torrents files intergrity check on adding each torrent. Disable this will free some cpu usage on adding operation."
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user