разделение поиска на уровне клиента
This commit is contained in:
		
							
								
								
									
										28
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								index.js
									
									
									
									
									
								
							| @ -149,7 +149,7 @@ io.on('connection', function(socket) | ||||
| 		}); | ||||
| 	}); | ||||
|  | ||||
| 	socket.on('search', function(text, callback) | ||||
| 	socket.on('searchTorrent', function(text, navigation, callback) | ||||
| 	{ | ||||
| 		if(typeof callback != 'function') | ||||
| 			return; | ||||
| @ -159,25 +159,37 @@ io.on('connection', function(socket) | ||||
| 			return; | ||||
| 		} | ||||
|  | ||||
| 		const index = navigation.index || 0; | ||||
| 		const limit = navigation.limit || 10; | ||||
| 		let search = {}; | ||||
|  | ||||
| 		console.log(text); | ||||
| 		let q = 2; | ||||
| 		socketMysql.query('SELECT * FROM `torrents` WHERE MATCH(`name`) AGAINST(?) LIMIT 10', text, function (error, rows, fields) { | ||||
| 		socketMysql.query('SELECT * FROM `torrents` WHERE MATCH(`name`) AGAINST(?) LIMIT ?,?', [text, index, limit], function (error, rows, fields) { | ||||
| 			rows.forEach((row) => { | ||||
| 		  		search[row.hash] = baseRowData(row); | ||||
| 		  	}); | ||||
| 		  	if(--q == 0) | ||||
| 		  	callback(Object.keys(search).map(function(key) { | ||||
| 			    return search[key]; | ||||
| 			})); | ||||
| 		}); | ||||
| 		socketMysql.query('SELECT * FROM `files` INNER JOIN torrents ON(torrents.hash = files.hash) WHERE MATCH(`path`) AGAINST(?) LIMIT 10', text, function (error, rows, fields) { | ||||
| 	}); | ||||
|  | ||||
| 	socket.on('searchFiles', function(text, navigation, callback) | ||||
| 	{ | ||||
| 		if(typeof callback != 'function') | ||||
| 			return; | ||||
|  | ||||
| 		if(!text || text.length <= 2) { | ||||
| 			callback(undefined); | ||||
| 			return; | ||||
| 		} | ||||
|  | ||||
| 		const index = navigation.index || 0; | ||||
| 		const limit = navigation.limit || 10; | ||||
| 		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) { | ||||
| 			rows.forEach((row) => { | ||||
| 		  		search[row.hash] = baseRowData(row); | ||||
| 		  		search[row.hash].path = row.path; | ||||
| 		  	}); | ||||
| 		  	if(--q == 0) | ||||
| 		  	callback(Object.keys(search).map(function(key) { | ||||
| 			    return search[key]; | ||||
| 			})); | ||||
|  | ||||
| @ -18,11 +18,31 @@ export default class Search extends Component { | ||||
|     this.setState({ | ||||
|       searchingIndicator: true | ||||
|     }); | ||||
|     window.torrentSocket.emit('search', this.searchValue, (torrents) => { | ||||
|       this.searchData = torrents; | ||||
|     this.searchData = []; | ||||
|     let queries = 2; | ||||
|     window.torrentSocket.emit('searchTorrent', this.searchValue, {limit: 10}, (torrents) => { | ||||
|       if(torrents) { | ||||
|         this.searchData = this.searchData.concat(torrents); | ||||
|       } | ||||
|       if(--queries == 0) { | ||||
|         this.setState({ | ||||
|           searchingIndicator: false | ||||
|         }); | ||||
|       } else { | ||||
|         this.forceUpdate(); | ||||
|       } | ||||
|     }); | ||||
|     window.torrentSocket.emit('searchFiles', this.searchValue, {limit: 10}, (torrents) => { | ||||
|       if(torrents) { | ||||
|         this.searchData = this.searchData.concat(torrents); | ||||
|       } | ||||
|       if(--queries == 0) { | ||||
|         this.setState({ | ||||
|           searchingIndicator: false | ||||
|         }); | ||||
|       } else { | ||||
|         this.forceUpdate(); | ||||
|       } | ||||
|     }); | ||||
|   } | ||||
|   componentDidMount() { | ||||
| @ -65,7 +85,7 @@ export default class Search extends Component { | ||||
|         { | ||||
|             this.stats | ||||
|             ? | ||||
|             <div className='fs0-75' style={{color: 'rgba(0, 0, 0, 0.541176)'}}>we have information about {this.stats.torrents} torrents and around {this.stats.files} files and { formatBytes(this.stats.size, 1) } of data</div> | ||||
|             <div className='fs0-75 pad0-75' style={{color: 'rgba(0, 0, 0, 0.541176)'}}>we have information about {this.stats.torrents} torrents and around {this.stats.files} files and { formatBytes(this.stats.size, 1) } of data</div> | ||||
|             : | ||||
|             null | ||||
|         } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user