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:
Alexey Kasyanchuk 2018-08-06 17:56:21 +03:00
parent 3743a60bec
commit e7b035a1a8
6 changed files with 68 additions and 33 deletions

View File

@ -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 className='fs0-75' style={{color: 'grey'}}>* {__('Enable torrents replication from another rats clients. Dont recomended if torrent scanner works correct')}.</div>
</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> <div style={{marginTop: 10}}>{__('Torrent network scanner settings')}:</div>

View File

@ -59,6 +59,7 @@ let config = {
cleanupDiscLimit: 7 * 1024 * 1024 * 1024, cleanupDiscLimit: 7 * 1024 * 1024 * 1024,
spaceQuota: false, spaceQuota: false,
spaceDiskLimit: 7 * 1024 * 1024 * 1024, spaceDiskLimit: 7 * 1024 * 1024 * 1024,
recheckFilesOnAdding: true,
dbPath: '', dbPath: '',

View File

@ -384,6 +384,42 @@ module.exports = function (send, recive, dataDirectory, version, env)
torrent.id = torrentsId++; 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) => { sphinxSingle.query("SELECT id FROM torrents WHERE hash = ?", torrent.hash, (err, single) => {
if(!single) if(!single)
{ {
@ -392,11 +428,21 @@ module.exports = function (send, recive, dataDirectory, version, env)
return return
} }
// torrent already probably in db
if(single.length > 0) if(single.length > 0)
{ {
if(config.recheckFilesOnAdding)
{
// recheck files and if they not ok add their to database
recheckFiles(addFilesToDatabase)
}
resolve() resolve()
return return
} }
else
{
addFilesToDatabase()
}
torrent.nameIndex = torrent.name torrent.nameIndex = torrent.name
@ -423,36 +469,6 @@ module.exports = function (send, recive, dataDirectory, version, env)
events.emit('insert', torrent) 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) => { const removeTorrentFromDB = async (torrent) => {

View File

@ -185,6 +185,8 @@
"calculation": "calculation", "calculation": "calculation",
"removing": "removing", "removing": "removing",
"Torrents cleaned": "Torrents cleaned", "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."
} }
} }

View File

@ -185,6 +185,8 @@
"calculation": "подсчитывается", "calculation": "подсчитывается",
"removing": "удаляется", "removing": "удаляется",
"Torrents cleaned": "Торренты очещены", "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.": "Включить проверку целостности файлов в базе при добавлении каждого торрента. Отключение этой опции освободит некоторорое количество ресурсов процессора при добавлении."
} }
} }

View File

@ -185,6 +185,8 @@
"calculation": "calculation", "calculation": "calculation",
"removing": "removing", "removing": "removing",
"Torrents cleaned": "Torrents cleaned", "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."
} }
} }