исправление возможной ошибки запроса

This commit is contained in:
Alexey Kasyanchuk 2017-01-04 21:19:14 +03:00
parent dd23b56988
commit 916c421a19
4 changed files with 32 additions and 8 deletions

View File

@ -87,6 +87,11 @@ io.on('connection', function(socket)
return; return;
socketMysql.query('SELECT * FROM `torrents` ORDER BY added DESC LIMIT 0,10', function (error, rows, fields) { socketMysql.query('SELECT * FROM `torrents` ORDER BY added DESC LIMIT 0,10', function (error, rows, fields) {
if(!rows) {
callback(undefined)
return;
}
let torrents = []; let torrents = [];
rows.forEach((row) => { rows.forEach((row) => {
torrents.push(baseRowData(row)); torrents.push(baseRowData(row));
@ -102,6 +107,11 @@ io.on('connection', function(socket)
return; return;
socketMysql.query('SELECT * FROM `statistic`', function (error, rows, fields) { socketMysql.query('SELECT * FROM `statistic`', function (error, rows, fields) {
if(!rows) {
callback(undefined)
return;
}
callback(rows[0]) callback(rows[0])
}); });
}); });
@ -115,8 +125,8 @@ io.on('connection', function(socket)
return; return;
socketMysql.query('SELECT * FROM `torrents` WHERE `hash` = ?', hash, function (error, rows, fields) { socketMysql.query('SELECT * FROM `torrents` WHERE `hash` = ?', hash, function (error, rows, fields) {
if(rows.length == 0) { if(!rows || rows.length == 0) {
callback(undefined); callback(undefined)
return; return;
} }
let torrent = rows[0]; let torrent = rows[0];
@ -149,6 +159,10 @@ io.on('connection', function(socket)
const limit = navigation.limit || 10; const limit = navigation.limit || 10;
let search = {}; let search = {};
socketMysql.query('SELECT * FROM `torrents` WHERE MATCH(`name`) AGAINST(?) LIMIT ?,?', [text, index, limit], function (error, rows, fields) { socketMysql.query('SELECT * FROM `torrents` WHERE MATCH(`name`) AGAINST(?) LIMIT ?,?', [text, index, limit], function (error, rows, fields) {
if(!rows) {
callback(undefined)
return;
}
rows.forEach((row) => { rows.forEach((row) => {
search[row.hash] = baseRowData(row); search[row.hash] = baseRowData(row);
}); });
@ -172,6 +186,10 @@ io.on('connection', function(socket)
const limit = navigation.limit || 10; const limit = navigation.limit || 10;
let search = {}; let search = {};
socketMysql.query('SELECT * FROM `files` INNER JOIN torrents ON(torrents.hash = files.hash) WHERE MATCH(`path`) AGAINST(?) LIMIT ?,?', [text, index, limit], function (error, rows, fields) { socketMysql.query('SELECT * FROM `files` INNER JOIN torrents ON(torrents.hash = files.hash) WHERE MATCH(`path`) AGAINST(?) LIMIT ?,?', [text, index, limit], function (error, rows, fields) {
if(!rows) {
callback(undefined)
return;
}
rows.forEach((row) => { rows.forEach((row) => {
search[row.hash] = baseRowData(row); search[row.hash] = baseRowData(row);
search[row.hash].path = row.path; search[row.hash].path = row.path;

View File

@ -149,8 +149,10 @@ export default class RecentTorrents extends Component {
} }
componentDidMount() { componentDidMount() {
window.torrentSocket.emit('recentTorrents', (data) => { window.torrentSocket.emit('recentTorrents', (data) => {
if(data) {
this.torrents = data; this.torrents = data;
this.forceUpdate(); this.forceUpdate();
}
}); });
this.newTorrentFunc = (torrent) => { this.newTorrentFunc = (torrent) => {
this.torrents.unshift(torrent); this.torrents.unshift(torrent);

View File

@ -47,8 +47,10 @@ export default class Search extends Component {
} }
componentDidMount() { componentDidMount() {
this.newStatisticFunc = (statistic) => { this.newStatisticFunc = (statistic) => {
if(statistic) {
this.stats = statistic; this.stats = statistic;
this.forceUpdate(); this.forceUpdate();
}
}; };
window.torrentSocket.emit('statistic', this.newStatisticFunc); window.torrentSocket.emit('statistic', this.newStatisticFunc);
window.torrentSocket.on('newStatistic', this.newStatisticFunc); window.torrentSocket.on('newStatistic', this.newStatisticFunc);

View File

@ -138,8 +138,10 @@ export default class TorrentPage extends Component {
}; };
componentDidMount() { componentDidMount() {
window.torrentSocket.emit('torrent', this.props.hash, {files: true}, (data) => { window.torrentSocket.emit('torrent', this.props.hash, {files: true}, (data) => {
if(data) {
this.torrent = data this.torrent = data
this.forceUpdate(); this.forceUpdate();
}
}); });
} }
render() { render() {