fix(search): fix slow query wrong remote response on search

This commit is contained in:
Alexey Kasyanchuk
2021-02-22 03:09:54 +03:00
parent 9d684b89a6
commit 5a712f77b5
5 changed files with 43 additions and 16 deletions

View File

@ -79,9 +79,9 @@ module.exports = async ({
}
const mergeTorrentsWithDownloadsFn = (Fn, copy) => (...args) => {
const callback = args[args.length - 1]
const rest = args.slice(0, -1)
Fn(...rest, (data) => callback(mergeTorrentsWithDownloads(data, copy)))
const callback = args[args.length - 2]
const rest = args.slice(0, -2)
Fn(...rest, (data) => callback(mergeTorrentsWithDownloads(data, copy)), args[args.length - 1])
}
const downloadFilesList = (torrent) => torrent.files.map((file, index) => ({
@ -393,7 +393,7 @@ module.exports = async ({
});
}
recive('searchTorrent', mergeTorrentsWithDownloadsFn((text, navigation, callback) => {
recive('searchTorrent', mergeTorrentsWithDownloadsFn((text, navigation, callback, id) => {
searchTorrentCall(text, navigation, callback)
p2p.emit('searchTorrent', {text, navigation}, (remote, socketObject) => {
logT('search', 'remote search results', remote && remote.length)
@ -403,7 +403,7 @@ module.exports = async ({
const peer = { address: socket.remoteAddress, port: socket.remotePort }
remote = remote.map(torrent => Object.assign(torrent, {peer}))
}
send('remoteSearchTorrent', mergeTorrentsWithDownloads(remote))
send('remoteSearchTorrent', {torrents: mergeTorrentsWithDownloads(remote), id})
})
}));
@ -485,7 +485,7 @@ module.exports = async ({
});
}
recive('searchFiles', mergeTorrentsWithDownloadsFn((text, navigation, callback) => {
recive('searchFiles', mergeTorrentsWithDownloadsFn((text, navigation, callback, id) => {
searchFilesCall(text, navigation, callback)
p2p.emit('searchFiles', {text, navigation}, (remote, socketObject) => {
logT('search', 'remote search files results', remote && remote.length)
@ -495,7 +495,7 @@ module.exports = async ({
const peer = { address: socket.remoteAddress, port: socket.remotePort }
remote = remote.map(torrent => Object.assign(torrent, {peer}))
}
send('remoteSearchFiles', mergeTorrentsWithDownloads(remote))
send('remoteSearchFiles', {torrents: mergeTorrentsWithDownloads(remote), id})
})
}));

View File

@ -317,6 +317,7 @@ app.on("ready", async () => {
if(mainWindow)
mainWindow.webContents.send('callback', id, JSON.stringify(responce))
}
arg.push(id);
}
callback.apply(null, arg)
})

View File

@ -69,7 +69,10 @@ io.on('connection', (socket) =>
{
for(const message in socketMessages)
{
socket.on(message, socketMessages[message])
socket.on(message, (...data) => {
const id = data.shift();
socketMessages[message](...data, id)
})
}
})