fix(filter): cleaning fix on big db

This commit is contained in:
Alexey Kasyanchuk 2018-04-03 12:01:19 +03:00
parent 0e9e40be02
commit e581d95194
2 changed files with 23 additions and 17 deletions

View File

@ -1,4 +1,5 @@
const ipaddr = require('ipaddr.js');
import forBigTable from './forBigTable'
module.exports = ({
sphinx,
@ -622,23 +623,10 @@ module.exports = ({
console.log('removed torrents by filter:', toRemove.length)
}
const checker = (index = 0) => {
sphinx.query(`SELECT * FROM torrents LIMIT ${index},50000`, (err, torrents) => {
if(err || torrents.length == 0)
{
done()
return
}
torrents.forEach((torrent) => {
forBigTable(sphinx, 'torrents', (torrent) => {
if(!checkTorrent(torrent))
toRemove.push(torrent)
})
checker(index + torrents.length)
});
}
checker()
}, done)
})
let socketIPV4 = () => {

View File

@ -0,0 +1,18 @@
export default (sphinx, table, callback, doneCallback, max = 1000) => new Promise((done) => {
const checker = (index = 0) => {
sphinx.query(`SELECT * FROM ${table} WHERE id > ${index} LIMIT ${max}`, (err, torrents) => {
if(err || torrents.length == 0)
{
if(err)
console.log('big table parse error', err)
if(doneCallback)
doneCallback(true)
done(true)
return
}
torrents.forEach(callback)
checker(torrents[torrents.length - 1].id)
});
}
checker()
})