astyle
This commit is contained in:
parent
8adcdac6f4
commit
805c55849a
@ -1,5 +1,5 @@
|
|||||||
module.exports = async function asyncForEach(array, callback) {
|
module.exports = async function asyncForEach(array, callback) {
|
||||||
for (let index = 0; index < array.length; index++) {
|
for (let index = 0; index < array.length; index++) {
|
||||||
await callback(array[index], index, array)
|
await callback(array[index], index, array)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -196,7 +196,7 @@ module.exports = async (callback, mainWindow, sphinxApp) => {
|
|||||||
let i = 1
|
let i = 1
|
||||||
const torrents = (await sphinx.query("SELECT COUNT(*) AS c FROM torrents"))[0].c
|
const torrents = (await sphinx.query("SELECT COUNT(*) AS c FROM torrents"))[0].c
|
||||||
|
|
||||||
const torrentsArray = []
|
let torrentsArray = []
|
||||||
|
|
||||||
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, ']')
|
||||||
@ -247,12 +247,14 @@ module.exports = async (callback, mainWindow, sphinxApp) => {
|
|||||||
await sphinx.insertValues('torrents', torrent)
|
await sphinx.insertValues('torrents', torrent)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
torrentsArray = null
|
||||||
|
|
||||||
console.log('optimizing torrents')
|
console.log('optimizing torrents')
|
||||||
if(patchWindow)
|
if(patchWindow)
|
||||||
patchWindow.webContents.send('optimize', {field: 'torrents'})
|
patchWindow.webContents.send('optimize', {field: 'torrents'})
|
||||||
sphinx.query(`OPTIMIZE INDEX torrents`)
|
sphinx.query(`OPTIMIZE INDEX torrents`)
|
||||||
await sphinxApp.waitOptimized('torrents')
|
await sphinxApp.waitOptimized('torrents')
|
||||||
|
|
||||||
await setVersion(5)
|
await setVersion(5)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,10 +14,10 @@ const writeSphinxConfig = (path, dbPath) => {
|
|||||||
index torrents
|
index torrents
|
||||||
{
|
{
|
||||||
type = rt
|
type = rt
|
||||||
path = ${dbPath}/database/torrents
|
path = ${dbPath}/database/torrents
|
||||||
|
|
||||||
min_prefix_len = 3
|
min_prefix_len = 3
|
||||||
expand_keywords = 1
|
expand_keywords = 1
|
||||||
|
|
||||||
rt_attr_string = hash
|
rt_attr_string = hash
|
||||||
rt_attr_string = name
|
rt_attr_string = name
|
||||||
@ -143,78 +143,78 @@ const writeSphinxConfig = (path, dbPath) => {
|
|||||||
module.exports = (callback, dataDirectory, onClose) => {
|
module.exports = (callback, dataDirectory, onClose) => {
|
||||||
const start = (callback) => {
|
const start = (callback) => {
|
||||||
|
|
||||||
const sphinxPath = path.resolve(appPath('searchd'))
|
const sphinxPath = path.resolve(appPath('searchd'))
|
||||||
console.log('Sphinx Path:', sphinxPath)
|
console.log('Sphinx Path:', sphinxPath)
|
||||||
|
|
||||||
const sphinxConfigDirectory = dataDirectory
|
const sphinxConfigDirectory = dataDirectory
|
||||||
appConfig['dbPath'] = appConfig.dbPath && appConfig.dbPath.length > 0 ? appConfig.dbPath : sphinxConfigDirectory;
|
appConfig['dbPath'] = appConfig.dbPath && appConfig.dbPath.length > 0 ? appConfig.dbPath : sphinxConfigDirectory;
|
||||||
// on portable dir can move database directory
|
// on portable dir can move database directory
|
||||||
if(!fs.existsSync(appConfig.dbPath) && fs.existsSync(sphinxConfigDirectory))
|
if(!fs.existsSync(appConfig.dbPath) && fs.existsSync(sphinxConfigDirectory))
|
||||||
{
|
|
||||||
appConfig['dbPath'] = sphinxConfigDirectory
|
|
||||||
}
|
|
||||||
|
|
||||||
const { isInitDb } = writeSphinxConfig(sphinxConfigDirectory, appConfig.dbPath)
|
|
||||||
|
|
||||||
const config = `${sphinxConfigDirectory}/sphinx.conf`
|
|
||||||
const options = ['--config', config]
|
|
||||||
if(!(/^win/.test(process.platform)))
|
|
||||||
{
|
|
||||||
options.push('--nodetach')
|
|
||||||
}
|
|
||||||
const sphinx = spawn(sphinxPath, options)
|
|
||||||
// remeber initizalizing of db
|
|
||||||
sphinx.start = start
|
|
||||||
sphinx.isInitDb = isInitDb
|
|
||||||
sphinx.directoryPath = appConfig.dbPath
|
|
||||||
sphinx.directoryPathDb = appConfig.dbPath + '/database'
|
|
||||||
|
|
||||||
const optimizeResolvers = {}
|
|
||||||
|
|
||||||
sphinx.stdout.on('data', (data) => {
|
|
||||||
console.log(`sphinx: ${data}`)
|
|
||||||
if (data.includes('accepting connections')) {
|
|
||||||
console.log('catched sphinx start')
|
|
||||||
if(callback)
|
|
||||||
callback()
|
|
||||||
}
|
|
||||||
|
|
||||||
const checkOptimized = String(data).match(/index ([\w]+): optimized/)
|
|
||||||
if(checkOptimized)
|
|
||||||
{
|
{
|
||||||
if(optimizeResolvers[checkOptimized[1]])
|
appConfig['dbPath'] = sphinxConfigDirectory
|
||||||
{
|
}
|
||||||
console.log('resolve optimizer', checkOptimized[1])
|
|
||||||
optimizeResolvers[checkOptimized[1]]()
|
const { isInitDb } = writeSphinxConfig(sphinxConfigDirectory, appConfig.dbPath)
|
||||||
|
|
||||||
|
const config = `${sphinxConfigDirectory}/sphinx.conf`
|
||||||
|
const options = ['--config', config]
|
||||||
|
if(!(/^win/.test(process.platform)))
|
||||||
|
{
|
||||||
|
options.push('--nodetach')
|
||||||
|
}
|
||||||
|
const sphinx = spawn(sphinxPath, options)
|
||||||
|
// remeber initizalizing of db
|
||||||
|
sphinx.start = start
|
||||||
|
sphinx.isInitDb = isInitDb
|
||||||
|
sphinx.directoryPath = appConfig.dbPath
|
||||||
|
sphinx.directoryPathDb = appConfig.dbPath + '/database'
|
||||||
|
|
||||||
|
const optimizeResolvers = {}
|
||||||
|
|
||||||
|
sphinx.stdout.on('data', (data) => {
|
||||||
|
console.log(`sphinx: ${data}`)
|
||||||
|
if (data.includes('accepting connections')) {
|
||||||
|
console.log('catched sphinx start')
|
||||||
|
if(callback)
|
||||||
|
callback()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const checkOptimized = String(data).match(/index ([\w]+): optimized/)
|
||||||
|
if(checkOptimized)
|
||||||
|
{
|
||||||
|
if(optimizeResolvers[checkOptimized[1]])
|
||||||
|
{
|
||||||
|
console.log('resolve optimizer', checkOptimized[1])
|
||||||
|
optimizeResolvers[checkOptimized[1]]()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
sphinx.on('close', (code, signal) => {
|
||||||
|
console.log(`sphinx closed with code ${code} and signal ${signal}`)
|
||||||
|
if(onClose && !sphinx.replaceOnClose) // sometime we don't want to call default callback
|
||||||
|
onClose()
|
||||||
|
if(sphinx.onClose)
|
||||||
|
sphinx.onClose()
|
||||||
|
})
|
||||||
|
|
||||||
|
sphinx.stop = (onFinish, replaceFinish) => {
|
||||||
|
console.log('sphinx closing...')
|
||||||
|
if(onFinish)
|
||||||
|
sphinx.onClose = onFinish
|
||||||
|
if(replaceFinish)
|
||||||
|
sphinx.replaceOnClose = true // sometime we don't want to call default callback
|
||||||
|
exec(`"${sphinxPath}" --config "${config}" --stopwait`)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
sphinx.on('close', (code, signal) => {
|
sphinx.waitOptimized = (table) => new Promise((resolve) => {
|
||||||
console.log(`sphinx closed with code ${code} and signal ${signal}`)
|
optimizeResolvers[table] = () => {
|
||||||
if(onClose && !sphinx.replaceOnClose) // sometime we don't want to call default callback
|
delete optimizeResolvers[table];
|
||||||
onClose()
|
resolve()
|
||||||
if(sphinx.onClose)
|
}
|
||||||
sphinx.onClose()
|
})
|
||||||
})
|
|
||||||
|
|
||||||
sphinx.stop = (onFinish, replaceFinish) => {
|
return sphinx
|
||||||
console.log('sphinx closing...')
|
|
||||||
if(onFinish)
|
|
||||||
sphinx.onClose = onFinish
|
|
||||||
if(replaceFinish)
|
|
||||||
sphinx.replaceOnClose = true // sometime we don't want to call default callback
|
|
||||||
exec(`"${sphinxPath}" --config "${config}" --stopwait`)
|
|
||||||
}
|
|
||||||
|
|
||||||
sphinx.waitOptimized = (table) => new Promise((resolve) => {
|
|
||||||
optimizeResolvers[table] = () => {
|
|
||||||
delete optimizeResolvers[table];
|
|
||||||
resolve()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return sphinx
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user