fix(patch): fix memory issue
This commit is contained in:
parent
805c55849a
commit
064c93c176
@ -198,13 +198,32 @@ module.exports = async (callback, mainWindow, sphinxApp) => {
|
|||||||
|
|
||||||
let torrentsArray = []
|
let torrentsArray = []
|
||||||
|
|
||||||
|
let patch = 1
|
||||||
await forBigTable(sphinx, 'torrents', async (torrent) => {
|
await forBigTable(sphinx, 'torrents', async (torrent) => {
|
||||||
console.log('remember index', torrent.id, torrent.name, '[', i, 'of', torrents, ']')
|
console.log('remember index', torrent.id, torrent.name, '[', i, 'of', torrents, ']')
|
||||||
if(patchWindow)
|
if(patchWindow)
|
||||||
patchWindow.webContents.send('reindex', {field: torrent.name, index: i++, all: torrents, torrent: true})
|
patchWindow.webContents.send('reindex', {field: torrent.name, index: i++, all: torrents, torrent: true})
|
||||||
|
|
||||||
torrentsArray.push(torrent)
|
torrentsArray.push(torrent)
|
||||||
|
// keep memory safe
|
||||||
|
if(torrentsArray.length >= 20000)
|
||||||
|
{
|
||||||
|
fs.writeFileSync(`${sphinxApp.directoryPath}/torrents.patch.${patch++}`, JSON.stringify(torrentsArray, null, 4), 'utf8');
|
||||||
|
console.log('write torrents dump', `${sphinxApp.directoryPath}/torrents.patch.${patch-1}`)
|
||||||
|
torrentsArray = []
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
// keep last elemets
|
||||||
|
if(torrentsArray.length > 0)
|
||||||
|
{
|
||||||
|
fs.writeFileSync(`${sphinxApp.directoryPath}/torrents.patch.${patch}`, JSON.stringify(torrentsArray, null, 4), 'utf8');
|
||||||
|
console.log('write torrents dump', `${sphinxApp.directoryPath}/torrents.patch.${patch}`)
|
||||||
|
torrentsArray = []
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
patch-- //no last patch
|
||||||
|
}
|
||||||
|
|
||||||
// stop sphinx
|
// stop sphinx
|
||||||
await new Promise((resolve) => {
|
await new Promise((resolve) => {
|
||||||
@ -237,6 +256,10 @@ module.exports = async (callback, mainWindow, sphinxApp) => {
|
|||||||
|
|
||||||
console.log('sphinx restarted, patch db now')
|
console.log('sphinx restarted, patch db now')
|
||||||
|
|
||||||
|
for(let k = 1; k <= patch; k++)
|
||||||
|
{
|
||||||
|
torrentsArray = JSON.parse(fs.readFileSync(`${sphinxApp.directoryPath}/torrents.patch.${k}`, 'utf8'))
|
||||||
|
console.log('read torrents dump', `${sphinxApp.directoryPath}/torrents.patch.${k}`)
|
||||||
await asyncForEach(torrentsArray, async (torrent) => {
|
await asyncForEach(torrentsArray, async (torrent) => {
|
||||||
console.log('update index', torrent.id, torrent.name, '[', i, 'of', torrents, ']')
|
console.log('update index', torrent.id, torrent.name, '[', i, 'of', torrents, ']')
|
||||||
if(patchWindow)
|
if(patchWindow)
|
||||||
@ -246,6 +269,17 @@ module.exports = async (callback, mainWindow, sphinxApp) => {
|
|||||||
await sphinx.query(`DELETE FROM torrents WHERE id = ${torrent.id}`)
|
await sphinx.query(`DELETE FROM torrents WHERE id = ${torrent.id}`)
|
||||||
await sphinx.insertValues('torrents', torrent)
|
await sphinx.insertValues('torrents', torrent)
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
await new Promise((resolve) => {
|
||||||
|
glob(`${sphinxApp.directoryPath}/torrents.patch.*`, function (er, files) {
|
||||||
|
files.forEach(file => {
|
||||||
|
console.log('clear dump file', file)
|
||||||
|
fs.unlinkSync(path.resolve(file))
|
||||||
|
})
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
torrentsArray = null
|
torrentsArray = null
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user