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:
@ -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) => {
|
||||
|
Reference in New Issue
Block a user