увеличена скорость получание информации о размерах
This commit is contained in:
parent
c13534fe68
commit
d8239466ce
25
btsearch.sql
25
btsearch.sql
@ -40,6 +40,29 @@ LOCK TABLES `files` WRITE;
|
|||||||
/*!40000 ALTER TABLE `files` ENABLE KEYS */;
|
/*!40000 ALTER TABLE `files` ENABLE KEYS */;
|
||||||
UNLOCK TABLES;
|
UNLOCK TABLES;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `statistic`
|
||||||
|
--
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `statistic`;
|
||||||
|
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||||
|
/*!40101 SET character_set_client = utf8 */;
|
||||||
|
CREATE TABLE `statistic` (
|
||||||
|
`size` bigint(20) unsigned DEFAULT NULL,
|
||||||
|
`files` bigint(20) unsigned DEFAULT NULL,
|
||||||
|
`torrents` int(10) unsigned DEFAULT NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Dumping data for table `statistic`
|
||||||
|
--
|
||||||
|
|
||||||
|
LOCK TABLES `statistic` WRITE;
|
||||||
|
/*!40000 ALTER TABLE `statistic` DISABLE KEYS */;
|
||||||
|
/*!40000 ALTER TABLE `statistic` ENABLE KEYS */;
|
||||||
|
UNLOCK TABLES;
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Table structure for table `torrents`
|
-- Table structure for table `torrents`
|
||||||
--
|
--
|
||||||
@ -79,4 +102,4 @@ UNLOCK TABLES;
|
|||||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||||
|
|
||||||
-- Dump completed on 2017-01-02 11:33:56
|
-- Dump completed on 2017-01-03 6:03:58
|
||||||
|
35
index.js
35
index.js
@ -74,6 +74,32 @@ app.get('*', function(req, res)
|
|||||||
res.sendfile(__dirname + '/build/index.html');
|
res.sendfile(__dirname + '/build/index.html');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// start
|
||||||
|
|
||||||
|
// обновление статистики
|
||||||
|
setInterval(() => {
|
||||||
|
let stats = {};
|
||||||
|
socketMysql.query('SELECT COUNT(*) as tornum FROM `torrents`', function (error, rows, fields) {
|
||||||
|
stats.torrents = rows[0].tornum;
|
||||||
|
socketMysql.query('SELECT COUNT(*) as filesnum, SUM(`size`) as filesizes FROM `files`', function (error, rows, fields) {
|
||||||
|
stats.files = rows[0].filesnum;
|
||||||
|
stats.size = rows[0].filesizes;
|
||||||
|
io.sockets.emit('newStatistic', stats);
|
||||||
|
socketMysql.query('DELETE FROM `statistic`', function (err, result) {
|
||||||
|
if(!result) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
socketMysql.query('INSERT INTO `statistic` SET ?', stats, function(err, result) {
|
||||||
|
if(!result) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}, 60 * 1000)
|
||||||
|
|
||||||
io.on('connection', function(socket)
|
io.on('connection', function(socket)
|
||||||
{
|
{
|
||||||
function baseRowData(row)
|
function baseRowData(row)
|
||||||
@ -109,13 +135,8 @@ io.on('connection', function(socket)
|
|||||||
if(typeof callback != 'function')
|
if(typeof callback != 'function')
|
||||||
return;
|
return;
|
||||||
|
|
||||||
let stats = {};
|
socketMysql.query('SELECT * FROM `statistic`', function (error, rows, fields) {
|
||||||
socketMysql.query('SELECT COUNT(*) as tornum FROM `torrents`', function (error, rows, fields) {
|
callback(rows[0])
|
||||||
stats.torrents = rows[0].tornum;
|
|
||||||
socketMysql.query('SELECT COUNT(*) as filesnum FROM `files`', function (error, rows, fields) {
|
|
||||||
stats.files = rows[0].filesnum;
|
|
||||||
callback(stats)
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -73,6 +73,9 @@ export default class RecentTorrents extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
|
if(!this.torrents || this.torrents.length == 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<List className='animated'>
|
<List className='animated'>
|
||||||
<Subheader inset={true}>Most recent torrents</Subheader>
|
<Subheader inset={true}>Most recent torrents</Subheader>
|
||||||
|
@ -5,6 +5,8 @@ import TextField from 'material-ui/TextField';
|
|||||||
import RaisedButton from 'material-ui/RaisedButton';
|
import RaisedButton from 'material-ui/RaisedButton';
|
||||||
import RefreshIndicator from 'material-ui/RefreshIndicator';
|
import RefreshIndicator from 'material-ui/RefreshIndicator';
|
||||||
|
|
||||||
|
import formatBytes from './format-bytes'
|
||||||
|
|
||||||
export default class Search extends Component {
|
export default class Search extends Component {
|
||||||
constructor(props)
|
constructor(props)
|
||||||
{
|
{
|
||||||
@ -28,6 +30,10 @@ export default class Search extends Component {
|
|||||||
this.stats = statistic;
|
this.stats = statistic;
|
||||||
this.forceUpdate();
|
this.forceUpdate();
|
||||||
});
|
});
|
||||||
|
window.torrentSocket.on('newStatistic', (statistic) => {
|
||||||
|
this.stats = statistic;
|
||||||
|
this.forceUpdate();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
const style = {
|
const style = {
|
||||||
@ -59,7 +65,7 @@ export default class Search extends Component {
|
|||||||
{
|
{
|
||||||
this.stats
|
this.stats
|
||||||
?
|
?
|
||||||
<div className='fs0-75' style={{color: 'rgba(0, 0, 0, 0.541176)'}}>we have {this.stats.torrents} torrents and around {this.stats.files} files here</div>
|
<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>
|
||||||
:
|
:
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user